Class SymbolTable

java.lang.Object
  extended by SymbolTable

public class SymbolTable
extends java.lang.Object

This class manages one or more symbol tables for a compiler. Tables are indexed from 0.


Field Summary
private  java.util.HashMap[] tables
           
 
Constructor Summary
SymbolTable()
          Construct a new SymbolTable manager with one table.
SymbolTable(int n)
          Construct a new SymbolTable manager with n tables.
 
Method Summary
 Symbol getSymbol(int k, java.lang.String key)
          Get a symbol from table[k].
 boolean isDeclared(int k, java.lang.String key)
          Check to see if a symbol is in table[k].
 boolean isDeclared(java.lang.String key)
          Check to see if a symbol is in any of the defined tables.
 Symbol putSymbol(int k, java.lang.String key, Symbol s)
          Add a symbol to table[k].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tables

private java.util.HashMap[] tables
Constructor Detail

SymbolTable

public SymbolTable()
Construct a new SymbolTable manager with one table.


SymbolTable

public SymbolTable(int n)
Construct a new SymbolTable manager with n tables.

Parameters:
n - number of distinct tables to manage.
Method Detail

putSymbol

public Symbol putSymbol(int k,
                        java.lang.String key,
                        Symbol s)
Add a symbol to table[k].

Parameters:
k - the table number to use. Must be 0 to n-1, where n is the number of defined tables.
key - the key (the symbol label) to use for this Symbol
s - the Symbol to add.
Returns:
a reference to the Symbol that was already in the table under this key, or null if this is a new entry.

getSymbol

public Symbol getSymbol(int k,
                        java.lang.String key)
Get a symbol from table[k].

Parameters:
k - the table number to use. Must be 0 to n-1, where n is the number of defined tables.
key - the key (the symbol label) used for this Symbol
Returns:
a reference to the Symbol that is in the table under this key, or null if the table contains no mapping for this key.

isDeclared

public boolean isDeclared(int k,
                          java.lang.String key)
Check to see if a symbol is in table[k].

Parameters:
k - the table number to use. Must be 0 to n-1, where n is the number of defined tables.
key - the key (the symbol label) used for this Symbol
Returns:
true or false depending on whether or not the symbol has already been declared.

isDeclared

public boolean isDeclared(java.lang.String key)
Check to see if a symbol is in any of the defined tables.

Parameters:
key - the key (the symbol label) used for this Symbol
Returns:
true or false depending on whether or not the symbol has already been declared.