[an error occurred while processing this directive]
import symtab.SymbolTable; import symtab.Descriptor;
For handling block structured languages, the symbol table is divided into levels, which correspond to blocks or scopes in a program. Each level can have its own Descriptor entries. When Descriptors are added, they are added to the highest level in the symbol table. Two Descriptors can be added with the same identifier as long as the entries are at different levels. When Descriptors are retrieved, they are retrieved from the highest level that contains an entry for the specified identifier.
Initially, the symbol table has a single level, identified as level 0. When enterScope() is called, a new level, with level number increased by 1, is added. When exitScope() is called, the highest level is removed, along with all of its Descriptor entries. The current level in the symbol table can be checked with a call to currentLevel().
The method level() returns the highest level that contains a Descriptor for its identifier argument, or -1 if there is no such level. The client should call this method prior to calling addDescriptor() or descriptorFor() to check if any Descriptor is defined for an identifier. A call to addDescriptor() should not be made if level() returns the current level. A call to descriptorFor() should not be made if level() returns -1.
Preconditions:
level(id) >= 0.
Preconditions:
level(id) < currentLevel().