Package symbols
Class SymbolTable
- java.lang.Object
-
- symbols.SymbolTable
-
public final class SymbolTable extends java.lang.ObjectThe SymbolTable class is used to store Symbol objects that have been generated during compilation.As compilation proceeds variables may be declared, which results in the creation of Symbol Objects. These are passed to an instance of SymbolTable and stored within an internal HashMap, from which the Symbols can be retrieved.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description SymbolTable()Constructs a SymbolTable object for storing Symbols that are declared during compilation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String name, java.lang.Object value, ObjectType type)Generate and add a Symbol object to the SymbolTable.voidadd(Symbol symbol)Add a Symbol object to the SymbolTable.voidclear()Clears the SymbolTable, removing all stored Symbol objects.booleancontains(java.lang.String name)Returns a boolean indicating whether the SymbolTable holds a particular Symbol.Symbolget(java.lang.String name)Returns a Symbol contained within the SymbolTable.voidprint()Pretty prints the SymbolTable to the console.voidremove(java.lang.String name)Remove a Symbol from the SymbolTable by its name.voidremove(Symbol symbol)Remove a Symbol from the SymbolTable.
-
-
-
Method Detail
-
contains
public boolean contains(java.lang.String name)
Returns a boolean indicating whether the SymbolTable holds a particular Symbol.If true, the SymbolTable contains the specified Symbol. If false, the Symbol is not present.
- Parameters:
name- A String identifying the Symbol by name- Returns:
- A boolean indicating if the SymbolTable contains a particular symbol
-
get
public Symbol get(java.lang.String name)
Returns a Symbol contained within the SymbolTable.Returns null if the symbol does not exist within the SymbolTable.
- Parameters:
name- A String identifying the Symbol by name- Returns:
- The specified Symbol object
-
add
public void add(Symbol symbol)
Add a Symbol object to the SymbolTable.- Parameters:
symbol- The symbol to be added
-
add
public void add(java.lang.String name, java.lang.Object value, ObjectType type)Generate and add a Symbol object to the SymbolTable.From the parameters, a Symbol object is generated and added to the SymbolTable.
If a Symbol with the same name already exists within the SymbolTable, its value and type are updated.
- Parameters:
name- The name of the symbolvalue- The value of the symboltype- The type of the symbol
-
remove
public void remove(Symbol symbol)
Remove a Symbol from the SymbolTable.- Parameters:
symbol- The symbol to be removed
-
remove
public void remove(java.lang.String name)
Remove a Symbol from the SymbolTable by its name.- Parameters:
name- The name of the symbol
-
clear
public void clear()
Clears the SymbolTable, removing all stored Symbol objects.
-
print
public void print()
Pretty prints the SymbolTable to the console.
-
-