Ejemplo n.º 1
0
        private void InsertVarEntry(string Lexeme, Symbol Token, int Depth)
        {
            var varEntry = new VarEntry()
            {
                Lexeme      = Lexeme,
                Token       = Token,
                Depth       = Depth,
                TypeOfEntry = EntryType.variableEntry,
            };

            var position = Hash(Lexeme);

            if (tableEntries[position] == null)
            {
                tableEntries[position] = new LinkedList <TableEntry>();

                tableEntries[position].AddFirst(varEntry);
            }
            else if (tableEntries[position].First != null && tableEntries[position].First.Value.Lexeme == Lexeme && tableEntries[position].First.Value.Depth == Depth)
            {
                Console.Write("Error at Line " + LexAnalyzer.LineNo + " : \"" + Lexeme + "\" is already defined. Press any key to exit....");
                Console.ReadKey();
                Environment.Exit(-1);
            }
            else
            {
                tableEntries[position].AddFirst(varEntry);
            }
        }
Ejemplo n.º 2
0
        public void Insert(string Lexeme, Symbol Token, int Depth, EntryType TypeOfEntry)
        {
            switch (TypeOfEntry)
            {
            case EntryType.classEntry: InsertClassEntry(Lexeme, Token, Depth); break;

            case EntryType.constEntry: InsertConstEntry(Lexeme, Token, Depth); break;

            case EntryType.functionEntry: InsertFuncEntry(Lexeme, Token, Depth); break;

            case EntryType.variableEntry: InsertVarEntry(Lexeme, Token, Depth);  break;

            default: Console.WriteLine("Error! Cannot insert into the symbol table"); break;
            }
        }