|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecttenua.symbol.Expression
public class Expression
A sequence of Symbols that are evaluated in order, like an RPN calculator
| Constructor Summary | |
|---|---|
Expression()
create a new empty Expression |
|
Expression(Symbol s)
create a new Expression that contains a single Symbol |
|
| Method Summary | |
|---|---|
Expression |
add(Expression e)
add all the contents of an existing Expression to the end of this |
Expression |
add(Symbol s)
add a Symbol to the end of this |
Vec |
eval(VariableMemento v)
evaluate this |
Vec |
eval(Vec d,
VariableMemento v)
evaluate this |
void |
eval(Vec d,
Vec result,
VariableMemento v)
evaluate this |
Assignment |
getAssignment(SymbolTable st)
returns an Assignment representing an assignment operation to this. |
boolean |
isConstant()
tests whether an expression is constant (no variables) |
Expression |
prepend(Expression e)
insert all the contents of an existing Expression to the start of this |
Expression |
prepend(Symbol s)
insert a Symbol to the start of this |
java.lang.String |
toString()
produces an RPN string, with variables listed as Variable[n]. |
java.lang.String |
toString(SymbolTable st)
produces a String representation of this expression. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Expression()
public Expression(Symbol s)
Symbol
| Method Detail |
|---|
public Expression add(Symbol s)
Symbol to the end of this
s - the Symbol to add
public Expression add(Expression e)
e - the Expression to add to this
public Expression prepend(Symbol s)
s - the Symbol to add
public Expression prepend(Expression e)
e - the Expression to add
public Assignment getAssignment(SymbolTable st)
Assignment representing an assignment operation to this.
valid only if this is a single Symbol which is a variable
st - the SymbolTable to use for error messages (using null will use
cryptic names (like "Variable[0]") but thhe method will work
UnexpectedSymbolException - if this cannot be assigned topublic Vec eval(VariableMemento v)
v - the memento representing the values of the variables.
if v == null, use the default values
public Vec eval(Vec d,
VariableMemento v)
d - the array of values to push onto the stack before evaluating.
Pushed in reverse order (the stack is created with DoubleStack.DoubleStack(nr.Vec).v - the memento representing the values of the variables.
if v == null, use the default values
public void eval(Vec d,
Vec result,
VariableMemento v)
d - the array of values to push onto the stack before evaluating.
Pushed in reverse order (the stack is created with DoubleStack.DoubleStack(nr.Vec).result - a copy of the values from the stack after evaluationv - the memento representing the values of the variables.
if v == null, use the default valuespublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toString(SymbolTable st)
SymbolTable.
parenthesizes only what is necessary by the rules of precedence.
This is rather kludgy, but it seems to work
st - the SymbolTable to use. If null, uses toString()
public boolean isConstant()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||