public final class SymbolTable
extends java.lang.Object
SymbolTable
class implements a symbol table.Constructor and Description |
---|
SymbolTable()
Creates a symbol table with a global scope.
|
Modifier and Type | Method and Description |
---|---|
void |
define(Symbol symbol)
Defines the specified symbol in the current scope.
|
void |
defineReserved(java.lang.Enum<?> kind,
java.lang.String[] names)
Defines reserved keywords by placing corresponding symbols
into the global scope.
|
boolean |
isReserved(java.lang.String name)
Checks whether the specified named was registered as reserved keyword.
|
SymbolScope |
peek()
Returns the current scope.
|
void |
pop()
Discards the current scope and replaces it with its outer scope.
|
void |
push()
Starts a new scope and sets it as the current scope.
|
void |
push(java.util.List<SymbolScope> scopes)
Sets the specified scope list as the current scope.
|
void |
push(SymbolScope scope)
Sets the specified scope as the current scope.
|
Symbol |
resolve(java.lang.String name)
Searches for a symbol by its name in the current scope and its outer scopes.
|
Symbol |
resolveMember(java.lang.String name)
Searches for a symbol by its name in the current scope only.
|
Symbol |
resolveNested(java.lang.String... names)
Searches for a symbol described by an array containing its name
preceded with names of the scopes the symbol is nested into.
|
public void defineReserved(java.lang.Enum<?> kind, java.lang.String[] names)
kind
- Symbol kind for reserved keywords.names
- Collection of keywords to be registered.public boolean isReserved(java.lang.String name)
name
- Name to be checked.true
if it is a reserved keyword of false
otherwise.public SymbolScope peek()
public void push()
public void push(SymbolScope scope)
scope
- Scope to be set as the current scope.java.lang.IllegalArgumentException
- if scope
is null
;
if scope
is not nested into the current scope.public void push(java.util.List<SymbolScope> scopes)
scopes
- List of scopes to be set as the current scope.java.lang.IllegalArgumentException
- if scopes
is null
or empty;
if scopes
are not nested into the current scope.public void pop()
java.lang.IllegalStateException
- if the current scope is the global scope
which cannot be discarded.public void define(Symbol symbol)
symbol
- Symbol to be defined.public Symbol resolve(java.lang.String name)
null
is returned.name
- Symbol name.null
if it is not defined.public Symbol resolveMember(java.lang.String name)
null
is returned.name
- Symbol name.null
if it is not defined.public Symbol resolveNested(java.lang.String... names)
null
is returned.names
- Array of names.null
if it is not defined.