Example #1
0
        /*************************************************************
        ** Function    : newProc                                    **
        ** Inputs      : None                                       **
        ** Return      : Void                                       **
        **************************************************************
        ** Description : makes a new procedure entry                **
        *************************************************************/
        void newProc(string lex)
        {
            tempP = new ProcedureEntry();

            int subList  = ObjTable.lookup(lex);
            int mainList = ObjTable.hashWrap(lex);

            List <int> tempLocs = new List <int>();

            tempLocs.Add(mainList);
            tempLocs.Add(subList);

            tempP.token  = Vari.Token;
            tempP.lexeme = lex;
            tempP.depth  = Vari.depth;
            tempP.type   = Vari.entryType;

            tempP.solocals = 0;
            tempP.soparams = 0;
            tempP.noparams = 0;
            tempP.toparams = new List <VarType>();
            tempP.passing  = new List <ModeType>();

            procNames.Push(tempP);
            ObjTable.theSymbolTable[mainList][subList] = tempP;
        }
Example #2
0
        /*************************************************************
        ** Function    : endProc                                    **
        ** Inputs      : None                                       **
        ** Return      : Void                                       **
        **************************************************************
        ** Description : closes the procedure entry                 **
        *************************************************************/
        void EndProc()
        {
            tempP.noparams = tempP.toparams.Count;
            tempP.solocals = Vari.offset[Vari.depth - 1];
            for (int i = 0; i < tempP.toparams.Count; ++i)
            {
                VarType type = tempP.toparams[i];
                if (type == VarType.charType)
                {
                    tempP.soparams += 1;
                }
                else if (type == VarType.intType)
                {
                    tempP.soparams += 2;
                }
                else if (type == VarType.floatType)
                {
                    tempP.soparams += 4;
                }
            }

            int subList  = ObjTable.lookup(tempP.lexeme);
            int mainList = ObjTable.hashWrap(tempP.lexeme);

            while (subList < ObjTable.theSymbolTable[mainList].Count && tempP.depth != ObjTable.theSymbolTable[mainList][subList].depth)
            {
                ++subList;
            }


            ObjTable.theSymbolTable[mainList][subList] = tempP;

            if (Vari.Lexeme != tempP.lexeme)
            {
                Console.WriteLine("Error: The Procedure name: " + tempP.lexeme + " does not match the end procedure name: " + Vari.Lexeme);
                Environment.Exit(1);
            }

            procNames.Pop();
            if (procNames.Count != 0)
            {
                tempP = procNames.Peek();
            }
        }