/// <summary> /// Takes the base items of a Table Entry, hashes and insert it into the symbol table /// </summary> /// <param name="lexeme"></param> /// <param name="symbol"></param> /// <param name="depth"></param> public void insert(string lexeme, Globals.Symbol symbol, int depth) { TableEntry found = lookup(lexeme); if (found == null) { LinkedList <TableEntry> lexemeList = new LinkedList <TableEntry>(); lexemeList.AddFirst(new VariableEntry() { lexeme = lexeme, tokenType = symbol, depth = depth, variableType = TableEntry.VariableType.intType, Offset = 0, size = 4 }); table.Add(hash(lexeme), lexemeList); } else if (found != null) { table[hash(lexeme)].AddFirst(new VariableEntry() { lexeme = lexeme, tokenType = symbol, depth = depth, variableType = TableEntry.VariableType.intType, Offset = 0, size = 4 }); } }
/// <summary> /// Match() Matches the current token to which is expected in the grammar /// </summary> /// <param name="token"></param> private void Match(Globals.Symbol token) { if (token == Globals.Token) { l.GetNextToken(); } else { Console.WriteLine($"Error: Line {Globals.LineNumber+1}: Expecting {token.ToString()}. Received {Globals.Token.ToString()}"); Environment.Exit(-1); } }