util
Class SymbolTable

java.lang.Object
  extended by util.SymbolTable

public class SymbolTable
extends java.lang.Object

Class for representing a class symbol table


Constructor Summary
SymbolTable()
          SymbolTable constructor create an empty symbol table
 
Method Summary
 void add(java.lang.String s, java.lang.Object value)
          Adds a symbol to the symbol table if one does not already exist Sets the value of the symbol to the specified parameter
 SymbolTable clone()
          clone this symbol table as well as all parent symbol tables Note: does a shallow clone, does not copy keys or values Note also: this is an expensive operation
 void dump()
          For debugging -- dumps out entire symbol table Starts from highest scope level (Object class) and works towards the lowest scope level (current level)
 void enterScope()
          Enter a new scope
 void exitScope()
          Exit a scope
 int getCurrScopeLevel()
          Gets the current scope level of the symbol table (first scope starts at 1)
 int getCurrScopeSize()
          Gets the number of entries in the current scope of the symbol table
 int getScopeLevel(java.lang.String s)
          Gets scope level of a symbol in the table (<0 means symbol not in table)
 int getSize()
          Gets the number of entries in all scopes of the symbol table Note: includes inherited scopes
 java.lang.Object lookup(java.lang.String s)
          Looks up a symbol in any scope in the symbol table
 java.lang.Object lookup(java.lang.String s, int level)
          Looks up a symbol in a particular scope in the symbol table as well as any outer scopes from that specified scope Note: an exception is thrown if the specified level is <0 or >= largest scope level
 java.lang.Object peek(java.lang.String s)
          Looks up a symbol in the current scope in the table
 java.lang.Object peek(java.lang.String s, int level)
          Looks up a symbol in a particular scope in the symbol table Note: an exception is thrown if the specified level is <0 or >= largest scope level
 void set(java.lang.String s, java.lang.Object val)
          Sets the value of an existing symbol in the innermost scope of the symbol table
 void set(java.lang.String s, java.lang.Object val, int level)
          Sets the value of an existing symbol in a particular scope of the symbol table (or an outer scope containing the specified scope)
 void setParent(SymbolTable parent)
          Set the parent symbol table
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SymbolTable

public SymbolTable()
SymbolTable constructor create an empty symbol table

Method Detail

setParent

public void setParent(SymbolTable parent)
Set the parent symbol table

Parameters:
parent - symbol table of the parent class

enterScope

public void enterScope()
Enter a new scope


exitScope

public void exitScope()
Exit a scope


add

public void add(java.lang.String s,
                java.lang.Object value)
Adds a symbol to the symbol table if one does not already exist Sets the value of the symbol to the specified parameter

Parameters:
s - symbol name (i.e., name of variable or method)
value - value of symbol (i.e., type)

lookup

public java.lang.Object lookup(java.lang.String s)
Looks up a symbol in any scope in the symbol table

Parameters:
s - string of symbol to lookup
Returns:
value of symbol (i.e., type), null if not found

lookup

public java.lang.Object lookup(java.lang.String s,
                               int level)
Looks up a symbol in a particular scope in the symbol table as well as any outer scopes from that specified scope Note: an exception is thrown if the specified level is <0 or >= largest scope level

Parameters:
s - string of symbol to lookup
level - scope level to lookup string (outermost scope is at level 0)
Returns:
value of symbol (i.e., type), null if not found in particular scope level

peek

public java.lang.Object peek(java.lang.String s)
Looks up a symbol in the current scope in the table

Parameters:
s - string of symbol to lookup
Returns:
value of symbol (i.e., type), null if not found

peek

public java.lang.Object peek(java.lang.String s,
                             int level)
Looks up a symbol in a particular scope in the symbol table Note: an exception is thrown if the specified level is <0 or >= largest scope level

Parameters:
s - string of symbol to lookup
level - scope level to lookup string (outermost scope is at level 0)
Returns:
value of symbol (i.e., type), null if not found in particular scope level

set

public void set(java.lang.String s,
                java.lang.Object val)
Sets the value of an existing symbol in the innermost scope of the symbol table

Parameters:
s - string of symbol to set
val - value to set the symbol to

set

public void set(java.lang.String s,
                java.lang.Object val,
                int level)
Sets the value of an existing symbol in a particular scope of the symbol table (or an outer scope containing the specified scope)

Parameters:
s - string of symbol to set
val - value to set the symbol to
level - scope level containing symbol to be set

getScopeLevel

public int getScopeLevel(java.lang.String s)
Gets scope level of a symbol in the table (<0 means symbol not in table)

Parameters:
s - string of symbol to lookup
Returns:
scope level

getSize

public int getSize()
Gets the number of entries in all scopes of the symbol table Note: includes inherited scopes

Returns:
size of current scope

getCurrScopeSize

public int getCurrScopeSize()
Gets the number of entries in the current scope of the symbol table

Returns:
size of current scope

getCurrScopeLevel

public int getCurrScopeLevel()
Gets the current scope level of the symbol table (first scope starts at 1)

Returns:
current scope level

clone

public SymbolTable clone()
clone this symbol table as well as all parent symbol tables Note: does a shallow clone, does not copy keys or values Note also: this is an expensive operation

Overrides:
clone in class java.lang.Object
Returns:
cloned symbol table

dump

public void dump()
For debugging -- dumps out entire symbol table Starts from highest scope level (Object class) and works towards the lowest scope level (current level)