vorläufige solution für aufgabe 2.1

This commit is contained in:
Ulf Gebhardt 2011-12-22 04:45:57 +01:00
parent 9e507d7734
commit 1cc74ba62f

View File

@ -12,16 +12,26 @@ public final class SymbolTable {
private List<List<String>> scopeStack;
public SymbolTable () {
symtab = new Map<String, Stack<Declaration>>();
scopeStack = new List<List<String>>();
}
// 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<String>());
}
// 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);
}
}