story.dbcore.grammars
Class SymbolTable

java.lang.Object
  extended by story.dbcore.grammars.SymbolTable
All Implemented Interfaces:
java.lang.Cloneable

public class SymbolTable
extends java.lang.Object
implements java.lang.Cloneable

Implements a symbol table for the command language. Allows the language to store and retrieve typed variables with separate typed declarations.


Constructor Summary
SymbolTable()
          Constructor with no outer scope
SymbolTable(SymbolTable outerScope)
          Constructor with pointer to outer scope
 
Method Summary
 java.lang.Object clone()
          Make a deep copy of the symbol table.
 void declare(VariableID ID, VariableType variableType)
          Declare a variable
 java.lang.Object define(VariableID ID, java.lang.Object value)
          Define a variable.
 java.lang.Object get(VariableID ID)
          Retrieve a variable
 VariableType getType(VariableID ID)
          Returns the VariableType of a variable.
 boolean isDeclared(VariableID ID)
          Returns whether a variable has been declared.
 boolean isDefined(VariableID ID)
          Returns whether a variable has been defined.
static SymbolTable mergeTables(SymbolTable first, SymbolTable second)
          Merge two symbol tables.
 int numDeclarations()
           
 java.lang.StringBuffer render()
          Render the symbol table (without any supertables) as a StringBuffer table with newline.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SymbolTable

public SymbolTable()
Constructor with no outer scope


SymbolTable

public SymbolTable(SymbolTable outerScope)
Constructor with pointer to outer scope

Method Detail

declare

public void declare(VariableID ID,
                    VariableType variableType)
             throws Scheherexception
Declare a variable

Throws:
Scheherexception

isDeclared

public boolean isDeclared(VariableID ID)
Returns whether a variable has been declared.


isDefined

public boolean isDefined(VariableID ID)
Returns whether a variable has been defined.


getType

public VariableType getType(VariableID ID)
                     throws Scheherexception
Returns the VariableType of a variable.

Throws:
Scheherexception

define

public java.lang.Object define(VariableID ID,
                               java.lang.Object value)
                        throws Scheherexception
Define a variable. Returns the value, possibly converted to a different type.

Throws:
Scheherexception

get

public java.lang.Object get(VariableID ID)
                     throws Scheherexception
Retrieve a variable

Throws:
Scheherexception

clone

public java.lang.Object clone()
Make a deep copy of the symbol table.

Overrides:
clone in class java.lang.Object

render

public java.lang.StringBuffer render()
                              throws Scheherexception
Render the symbol table (without any supertables) as a StringBuffer table with newline.

Throws:
Scheherexception

mergeTables

public static SymbolTable mergeTables(SymbolTable first,
                                      SymbolTable second)
                               throws Scheherexception
Merge two symbol tables. In case of duplicate variables, the second overwrites the first (even if the second is undefined and the first is defined). Note that this has the effect of flattening both tables; any outer-scope supertables will have their values copied into the new composite table.

Throws:
Scheherexception

numDeclarations

public int numDeclarations()


Copyright © 2011 David K. Elson. All Rights Reserved.