From 1cc74ba62ff35009bdf177a570e95b5c27d9ee08 Mon Sep 17 00:00:00 2001 From: rylon Date: Thu, 22 Dec 2011 04:45:57 +0100 Subject: [PATCH] =?UTF-8?q?vorl=C3=A4ufige=20solution=20f=C3=BCr=20aufgabe?= =?UTF-8?q?=202.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Uebungen/2. Uebung/c1-ex02/SymbolTable.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ws2011/Compiler I/Uebungen/2. Uebung/c1-ex02/SymbolTable.java b/ws2011/Compiler I/Uebungen/2. Uebung/c1-ex02/SymbolTable.java index daeeeb51..306c059d 100644 --- a/ws2011/Compiler I/Uebungen/2. Uebung/c1-ex02/SymbolTable.java +++ b/ws2011/Compiler I/Uebungen/2. Uebung/c1-ex02/SymbolTable.java @@ -12,16 +12,26 @@ public final class SymbolTable { private List> scopeStack; public SymbolTable () { + symtab = new Map>(); + scopeStack = new List>(); } // Opens a new level in the identification table, 1 higher than the // current topmost level. public void openScope () { + // new empty list + scopeStack.add(new List()); } // Closes the topmost level in the identification table, discarding // all entries belonging to that level. public void closeScope () { + //delete from symtab + for(int i = 0; i < scopeStack.get(scopeStack.size() -1).size(); i++){ + symtab.remove(scopeStack.get(scopeStack.size() -1).get(i)); + } + // delete top list + scopeStack.remove(scopeStack.size()-1); } // Makes a new entry in the identification table for the given identifier @@ -29,6 +39,8 @@ public final class SymbolTable { // duplicated is set to to true if there is already an entry for the // same identifier at the current level. public void enter (String id, Declaration attr) { + scopeStack.get(scopeStack.size()-1).add(id); + symtab.put(id, attr); } // Finds an entry for the given identifier in the identification table, @@ -37,7 +49,7 @@ public final class SymbolTable { // Returns null if no entry is found. // otherwise returns the attribute field of the entry found. public Declaration retrieve (String id) { - return null; + return symtab.containsKey(id); } }