public class SymbolTable extends Object
Constructor and Description |
---|
SymbolTable()
Create a new, empty symbol table with no parent table.
|
SymbolTable(SymbolTable parent)
Create a new, empty symbol table.
|
Modifier and Type | Method and Description |
---|---|
List<Symbol> |
getAllSymbols()
Gets all symbols accessible in this scope, which includes all symbols
defined at this level (from
getSymbols() ) plus all symbols defined
in any parent symbol table. |
List<Symbol> |
getInheritedSymbols()
Gets all symbols accessible in this scope that are not defined in this
scope; i.e., all symbols that are defined in a parent table.
|
List<Symbol> |
getSymbols()
Gets all symbols defined defined in this scope, in the order in which they were
added.
|
void |
insert(String name,
Symbol symbol)
Inserts a new symbol into the symbol table
|
Symbol |
lookup(String name)
Retrieves symbol information for a given symbol name.
|
int |
size()
Get accessible symbol count
|
String |
toString()
Builds a nicely-formatted list of new symbols declared from this scope.
|
String |
toString(int level)
Builds a nicely-formatted list of new symbols declared in this scope.
|
public SymbolTable()
public SymbolTable(SymbolTable parent)
parent
- Reference to parent table for enclosing scope.public void insert(String name, Symbol symbol) throws InvalidProgramException
name
- Decaf symbol namesymbol
- Symbol informationInvalidProgramException
- Thrown if the symbol is already definedpublic Symbol lookup(String name) throws InvalidProgramException
name
- Decaf symbol nameInvalidProgramException
- Thrown if the symbol is not foundpublic int size()
public List<Symbol> getSymbols()
public List<Symbol> getInheritedSymbols()
public List<Symbol> getAllSymbols()
getSymbols()
) plus all symbols defined
in any parent symbol table.public String toString()
public String toString(int level)
level
- Number of two-space indentations before each symbol.Copyright © 2019. All rights reserved.