public class CachingSymbolTable<T> extends Object
Constructor and Description |
---|
CachingSymbolTable()
Creates an empty symbol table with no open scope.
|
Modifier and Type | Method and Description |
---|---|
void |
closeScope()
Closes a lexical scope, removing all definitions within this scope.
|
Variable<T> |
get(String id)
Retrieves the type of an identifier, if any.
|
boolean |
has(String id)
Returns whether the given identifier is defined.
|
void |
openScope()
Opens a lexical scope.
|
Variable<T> |
put(String id,
T type)
Associates an identifier with a certain type in the current lexical scope.
|
public CachingSymbolTable()
public void openScope()
public void closeScope() throws EmptyStackException
EmptyStackException
- if no scope is openpublic Variable<T> put(String id, T type) throws Exception, EmptyStackException
id
- the name of the identifiertype
- the type of the identifierException
- if the identifier is declared in the current scope alreadyEmptyStackException
- if no scope is openpublic boolean has(String id) throws EmptyStackException
id
- the name of the identifierEmptyStackException
- if no scope is openpublic Variable<T> get(String id) throws Exception, EmptyStackException
id
- the name of the identifierException
- if the identifier is not definedEmptyStackException
- if no scope is open