Class SymbolTable
- java.lang.Object
-
- SymbolTable
-
public class SymbolTable extends java.lang.ObjectA table of symbols for a postscript interpreter. Uses java.util.HashMap for a simple, efficient implementation. We'll learn about the Map ADT and hashing soon.
-
-
Constructor Summary
Constructors Constructor Description SymbolTable()Constructs empty symbol table
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String symbol, Token value)Add a string and associated token to the tablebooleancontains(java.lang.String symbol)Check if a string is present in the tableTokenget(java.lang.String symbol)Retrieve the token associated with a string from the tableTokenremove(java.lang.String symbol)Remove a string and the associated token from the tablejava.lang.StringtoString()
-
-
-
Method Detail
-
contains
public boolean contains(java.lang.String symbol)
Check if a string is present in the table- Parameters:
symbol- String to check for in the table- Returns:
- true if symbol is in the table
-
add
public void add(java.lang.String symbol, Token value)Add a string and associated token to the table- Parameters:
symbol- String to add to the tablevalue- Token to associate with symbol Note: if symbol is already in the table, its associated Token will be replaced with value
-
get
public Token get(java.lang.String symbol)
Retrieve the token associated with a string from the table- Parameters:
symbol- String to retrieve from the table- Returns:
- returns Token associated with symbol
-
remove
public Token remove(java.lang.String symbol)
Remove a string and the associated token from the table- Parameters:
symbol- String to remove from the table- Returns:
- Token associated with symbol (or null if symbol is not present in the table)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- returns printable version of symbol table. Use with ptable.
-
-