Class VariableTable

java.lang.Object
  |
  +--VariableTable

public class VariableTable
extends java.lang.Object
implements VariableDereferencer

The VariableTable class acts in conjunction with the Variable class. For an introduction as to the nature of this relationship see the introduction to Variable.


Field Summary
protected  int capacity
          The current maximum number of elements possible
protected  int marksCapacity
          The current maximum number of marks possible
protected  int marksSize
          The current number of marks
protected  int size
          The current number of elements
protected  VariableReference[] variables
          The elements contained in the table
 
Constructor Summary
VariableTable()
          Creates a new empty table with a capacity of 20 elements
VariableTable(int i)
          Creates a new empty table with a capacity of i elements.
 
Method Summary
 void add(java.lang.String s)
          If s isn't already in the table, a new VariableReference with a name s and value 0 is added.
 void add(VariableReference v)
          Adds a VariableReference to the table.
 void assign(java.lang.String name, int value)
          Assigns value to the reference of name.
 void demark()
          Removes all variables from the table added since the last mark().
 int dereference(java.lang.String name)
          Returns the value for the variable with name of name.
 boolean exists(java.lang.String s)
          Same as isInTable(java.lang.String)
 boolean isInTable(java.lang.String s)
          Checks to see if there is a variable with name s in the table
 void mark()
          Places a mark in the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

capacity

protected int capacity
The current maximum number of elements possible

size

protected int size
The current number of elements

variables

protected VariableReference[] variables
The elements contained in the table

marksCapacity

protected int marksCapacity
The current maximum number of marks possible
See Also:
mark()

marksSize

protected int marksSize
The current number of marks
See Also:
mark()
Constructor Detail

VariableTable

public VariableTable()
Creates a new empty table with a capacity of 20 elements

VariableTable

public VariableTable(int i)
Creates a new empty table with a capacity of i elements. If i is 0 then the capacity is set to 1.
Method Detail

add

public void add(VariableReference v)
Adds a VariableReference to the table. If there is not room in the table for the symbol then (in the fashion of Vector) the capacity is doubled thereby making space.
Parameters:
o - reference to be added

add

public void add(java.lang.String s)
If s isn't already in the table, a new VariableReference with a name s and value 0 is added.
Specified by:
add in interface VariableDereferencer
Parameters:
s - name of a variable to add

assign

public void assign(java.lang.String name,
                   int value)
Assigns value to the reference of name. If there is no reference of name in the table then a new one is added with a value of value.
Specified by:
assign in interface VariableDereferencer
Parameters:
name - the name of the variable
value - the value to set name equal to

isInTable

public boolean isInTable(java.lang.String s)
Checks to see if there is a variable with name s in the table
Returns:
true if s is in the table

exists

public boolean exists(java.lang.String s)
Same as isInTable(java.lang.String)
Specified by:
exists in interface VariableDereferencer
Returns:
the same as isInTable(java.lang.String)

dereference

public int dereference(java.lang.String name)
Returns the value for the variable with name of name. If name is not in the table then a NotATableElementExcepetion will be thrown.
Specified by:
dereference in interface VariableDereferencer
Parameters:
name - variable name to derefernce

mark

public void mark()
Places a mark in the table. Marking is a process which allows for the localization of variables. When a point in the processing is reached where you wish to localize variables place a mark in the table and then when the table is demarked all variables put in since the mark are removed from the table.
Specified by:
mark in interface VariableDereferencer

demark

public void demark()
Removes all variables from the table added since the last mark(). If there are no marks then the talbe is cleared.
Specified by:
demark in interface VariableDereferencer