コード例 #1
0
        /*************************************************************
        ** Function    : insert                                     **
        ** Inputs      : lex, token, and depth                      **
        ** Return      : void                                       **
        **************************************************************
        ** Description : Inserts the lexeme, token and depth into a **
        **               record in the symbol table.                **
        **************************************************************/
        public void insert(string lex, Vari.Symbol Token, int depth)
        {
            int       x     = hash(lex);
            EntryNode entry = new EntryNode();

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

            if (theSymbolTable[x].Count != 0)
            {
                theSymbolTable[x].Insert(0, entry);
            }
            else
            {
                theSymbolTable[x].Add(entry);
            }
        }
コード例 #2
0
ファイル: RDParser.cs プロジェクト: amandowski/Ada-Compiler
        /*************************************************************
        ** Function    : Match                                      **
        ** Inputs      : Symbol                                     **
        ** Return      : Void                                       **
        **************************************************************
        ** Description : Checks if the wantedSymbol is equal to the **
        **               currentObject Symbol, else Error Message.  **
        *************************************************************/
        void Match(Vari.Symbol desiredSym)
        {
            if (Vari.Token == desiredSym)
            {
                if (!isSOS)
                {
                    int namesSize;
                    switch (Vari.Token)
                    {
                    case Vari.Symbol.proceduret:
                        isProc = true;
                        break;

                    case Vari.Symbol.idt:
                        if (isProc)
                        {
                            CheckDuplicates(Vari.Lexeme);
                            Vari.entryType = EntryType.procEntry;
                            ObjTable.insert(Vari.Lexeme, Vari.Token, Vari.depth);
                            newProc(Vari.Lexeme);
                        }
                        else
                        {
                            names.Add(Vari.Lexeme);
                        }
                        break;

                    case Vari.Symbol.integert:
                        if (isConst)
                        {
                            Vari.entryType = EntryType.constEntry;
                            namesSize      = names.Count;
                            for (int i = 0; i < namesSize; ++i)
                            {
                                CheckDuplicates(names[0]);
                                ObjTable.insert(names[0], Vari.Token, Vari.depth);
                                newConst(names[0], "integer");
                                names.RemoveAt(0);
                            }
                            isConst = false;
                        }
                        else
                        {
                            Vari.entryType = EntryType.varEntry;
                            Vari.varType   = VarType.intType;
                            namesSize      = names.Count;
                            for (int i = 0; i < namesSize; ++i)
                            {
                                CheckDuplicates(names[0]);
                                ObjTable.insert(names[0], Vari.Token, Vari.depth);
                                newVar(names[0]);
                                names.RemoveAt(0);
                            }
                        }
                        break;

                    case Vari.Symbol.floatt:
                        if (isConst)
                        {
                            Vari.entryType = EntryType.constEntry;
                            namesSize      = names.Count;
                            for (int i = 0; i < namesSize; ++i)
                            {
                                CheckDuplicates(names[0]);
                                ObjTable.insert(names[0], Vari.Token, Vari.depth);
                                newConst(names[0], "real");
                                names.RemoveAt(0);
                            }
                            isConst = false;
                        }
                        else
                        {
                            Vari.entryType = EntryType.varEntry;
                            Vari.varType   = VarType.floatType;
                            namesSize      = names.Count;
                            for (int i = 0; i < namesSize; ++i)
                            {
                                CheckDuplicates(names[0]);
                                ObjTable.insert(names[0], Vari.Token, Vari.depth);
                                newVar(names[0]);
                                names.RemoveAt(0);
                            }
                        }
                        break;

                    case Vari.Symbol.chart:
                        Vari.entryType = EntryType.varEntry;
                        Vari.varType   = VarType.charType;
                        namesSize      = names.Count;
                        for (int i = 0; i < namesSize; ++i)
                        {
                            CheckDuplicates(names[0]);
                            ObjTable.insert(names[0], Vari.Token, Vari.depth);
                            newVar(names[0]);

                            names.RemoveAt(0);
                        }
                        break;

                    case Vari.Symbol.constantt:
                        isConst = true;
                        break;

                    case Vari.Symbol.ist:
                        if (isProc)
                        {
                            IncrementDepth();
                            isProc = false;
                        }
                        break;

                    case Vari.Symbol.lparent:
                        if (isProc)
                        {
                            IncrementDepth();
                            isProc  = false;
                            isParam = true;
                        }
                        break;

                    case Vari.Symbol.rparent:
                        isParam = false;
                        break;

                    case Vari.Symbol.intt:
                        tempP.passing.Add(ModeType.inMode);
                        break;

                    case Vari.Symbol.inoutt:
                        tempP.passing.Add(ModeType.inoutMode);
                        break;

                    case Vari.Symbol.outt:
                        tempP.passing.Add(ModeType.outMode);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    if (Vari.Token == Vari.Symbol.idt)
                    {
                        int row = ObjTable.hashWrap(Vari.Lexeme);
                        int col = ObjTable.lookup(Vari.Lexeme);

                        if (col == -1)
                        {
                            Console.WriteLine("Error: there is an undeclared variable: " + Vari.Lexeme + " on line: " + Vari.lineNo);
                        }
                    }
                }

                Vari.myLex.getNextToken();
            }
            else if (Vari.Token == Vari.Symbol.eoftt)
            {
                return;
            }
            else
            {
                Console.WriteLine("Received: " + Vari.Token + " but expected: " + desiredSym);
                Environment.Exit(1);
            }
        }