tenua.symbol
Class Variable

java.lang.Object
  extended by tenua.symbol.Symbol
      extended by tenua.symbol.Value
          extended by tenua.symbol.Variable

public class Variable
extends Value

A Symbol that has a value that can be pushed onto the stack and can be changed. To allow for different states of the symbol table, a Variable has a default value but can pull its value from a VariableMemento.

Author:
Daniel Wachsstock

Field Summary
 
Fields inherited from class tenua.symbol.Value
ZERO
 
Fields inherited from class tenua.symbol.Symbol
CLEAR_STACK, maxPrecedence
 
Method Summary
 void assign(double d, VariableMemento v)
          assign a new value
 void eval(DoubleStack s, VariableMemento v)
          get the value
 double getValue(VariableMemento v)
          get the value
 void reset(VariableMemento v)
          set the value for this variable in a memento to the default
 java.lang.String toString()
           
 void toString(java.util.Stack stringStack, java.util.Stack precedenceStack, SymbolTable st)
          pushes a StringBuffer that reflects this Symbol, with all its arguments
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

eval

public void eval(DoubleStack s,
                 VariableMemento v)
get the value

Overrides:
eval in class Value
Parameters:
s - the stack to push onto
v - the memento to use. If v == null, use the default value

getValue

public double getValue(VariableMemento v)
get the value

Overrides:
getValue in class Value
Parameters:
v - the memento to use. If v==null, use the default value
Returns:
the value

assign

public void assign(double d,
                   VariableMemento v)
assign a new value

Parameters:
d - the new value
v - the memento to use. if v == null, assign to the default value

reset

public void reset(VariableMemento v)
set the value for this variable in a memento to the default

Parameters:
v - the memento. If v == null, does nothing

toString

public java.lang.String toString()
Overrides:
toString in class Value

toString

public void toString(java.util.Stack stringStack,
                     java.util.Stack precedenceStack,
                     SymbolTable st)
Description copied from class: Symbol
pushes a StringBuffer that reflects this Symbol, with all its arguments

Overrides:
toString in class Value
Parameters:
stringStack - the stack of StringBuffer from which to pop arguments and to which to push results
precedenceStack - a stack to be push'ed and pop'ed in parallel with stringStack that contains Integers, corresponding to the precedence of the arguments onstringStack. This is used to determine placement of parentheses. Anything other than a binary operation should push Symbol.maxPrecedence
st - the SymbolTable to get Symbol names from Note: the name is a misnomer; it uses StringBuffer's, not String's