Class SymbolTable
java.lang.Object
com.github.tom65536.adelante.symboltable.SymbolTable
Symbol table implementation.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionInitialize a new symbol table.protectedSymbolTable(SymbolTable aParent) Initialize a new symbol table. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Token token, DeclarationType kind) Add a symbol to the symbol table.booleancanAdd(Token token, DeclarationType kind) Report whether a symbol can be added to the current scope.Create a new symbol table whose parent is this table.Get the current packet name.Get the parent table.Look up a token of an identifier.Look up a symbol.voidsetPacketName(String aName) Set the current packet name.
-
Constructor Details
-
SymbolTable
public SymbolTable()Initialize a new symbol table. The symbol table is initialized with no parent. -
SymbolTable
Initialize a new symbol table.- Parameters:
aParent- the parent scope.
-
-
Method Details
-
setPacketName
Set the current packet name.- Parameters:
aName- the new name.
-
getPacketName
Get the current packet name. If the packet name is not set in the current scope this method recursively traverses the parent scopes.- Returns:
- the current packet or file name.
-
lookup
Look up a symbol.- Parameters:
id- the normalized identifier to be looked up.- Returns:
- a list of all matching definitions.
-
lookup
Look up a token of an identifier.- Parameters:
token- the identifier token.- Returns:
- a list of all matching definitions.
-
canAdd
Report whether a symbol can be added to the current scope.- Parameters:
token- the defining tokenkind- the kind of declaration to be added- Returns:
- true if the symbol can be added, false otherwise
-
add
Add a symbol to the symbol table.- Parameters:
token- the defining tokenkind- the declaration kind- Throws:
IllegalArgumentException- if the symbol cannot be added.
-
getParent
Get the parent table.- Returns:
- the parent table or
null.
-
createChild
Create a new symbol table whose parent is this table.- Returns:
- the created child parent table
-