public class SymTable { private int currentLevel = -1; private Entry last; public void openScope() { currentLevel++; } // Dumps all entries at the current level. public void closeScope() { Entry e = last; while (e != null && e.level == currentLevel) e = e.prev; last = e; currentLevel--; } // Adds a new Entry to our list. public void enter(String spelling, Node node, int type) { Entry e = new Entry(spelling, node, type, currentLevel); e.prev = last; last = e; } public void enter(String spelling, Node node, int type, int returntype) { Entry e = new Entry(spelling, node, type, currentLevel, returntype); e.prev = last; last = e; } // Looks for and returns an Entry whose name is same as spelling. public Entry lookup(String spelling) { for (Entry e = last; e != null; e = e.prev) if (spelling.compareTo(e.spelling) == 0) return e; return null; } public String toString() { String result = ""; for (Entry e = last; e != null; e = e.prev) result += e; return result; } }