minijava.symtable
Class SymbolTable<T extends Binding>

java.lang.Object
  extended by minijava.symtable.SymbolTable<T>

public class SymbolTable<T extends Binding>
extends java.lang.Object

A symbol table binds Symbol objects to Bindings. The implementation of this symbol table represents scoping with a tree-like structure. A SymbolTable has a parent SymbolTable reference that represents its parent superscope.

Author:
Santoso Wijaya
See Also:
Symbol, Binding

Constructor Summary
SymbolTable()
          Creates a symbol table on its own scope (i.e., no parent superscope).
SymbolTable(SymbolTable<T> parent)
          Creates a symbol table with the supplied argument as its parent super scope.
 
Method Summary
 void bind(java.lang.String sym, T binding)
          Binds the given symbol string to the given binding.
 void bind(Symbol symbol, T binding)
          Binds the given symbol to the given binding.
 SymbolTable<T> getSuperScope()
           
 T lookup(java.lang.String sym)
          Consults this symbol table with the given symbol string.
 T lookup(Symbol symbol)
          Consults this symbol table with the given symbol.
 java.lang.String toString()
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SymbolTable

public SymbolTable()
Creates a symbol table on its own scope (i.e., no parent superscope).


SymbolTable

public SymbolTable(SymbolTable<T> parent)
Creates a symbol table with the supplied argument as its parent super scope.

Parameters:
parent - the parent super scope symbol table
Method Detail

lookup

public T lookup(Symbol symbol)
Consults this symbol table with the given symbol. Returns the associated binding, or null if no such entry exists.

Parameters:
symbol - the symbol
Returns:
the binding associated with the symbol

lookup

public T lookup(java.lang.String sym)
Consults this symbol table with the given symbol string. Returns the associated binding, or null if no such entry exists.

Parameters:
sym - the symbol string
Returns:
the binding associated with the symbol string

bind

public void bind(Symbol symbol,
                 T binding)
Binds the given symbol to the given binding. Usually, the symbol table does not already contain such a binding.

Parameters:
symbol - the symbol
binding - the binding to associate with the givens symbol

bind

public void bind(java.lang.String sym,
                 T binding)
Binds the given symbol string to the given binding. Usually, the symbol table does not already contain such a binding.

Parameters:
sym - the symbol string
binding - the binding to associate with the givens symbol string

getSuperScope

public SymbolTable<T> getSuperScope()
Returns:
a reference to the symbol table that is the super scope of this one

toString

@Deprecated
public java.lang.String toString()
Deprecated. 

For debugging purposes. Only works for SymbolTable<Type>.

Overrides:
toString in class java.lang.Object
Returns:
string representation of this symbol table