tracer.expression
Class Expression

java.lang.Object
  |
  +--tracer.expression.Expression

public class Expression
extends java.lang.Object

The class representing an expression. Legal expression symbols include: all double precision numbers; arithmetic operators including '+', '-', '*', '/' and '^'; left bracket '(' and right bracket ')'; Three variables including 'x' (or 'X'), 'y' (or 'Y') and 'z' (or 'Z'); And many unary functions such as 'COS', 'SIN', etc.


Field Summary
 ExprNode enode
          The root expression node generated by parsing the expression string.
 java.util.Vector symQueue
          The symbol queue created for operator-precedence parsing.
 java.util.Stack symStack
          The operator, expression node stack created for operator-precedence parsing.
 
Constructor Summary
Expression()
          Construct an empty expression.
Expression(java.lang.String expr)
          Construct an expression by a string representation.
 
Method Summary
 boolean appendSymbol(Symbol sym)
          Append a symbol to the end of an expression.
 double eval()
          Evaluate the expression.
 java.lang.String getErrMsg()
          Return a string indicates where the parsing error occurs.
static Symbol nextSymbol(java.io.StreamTokenizer st)
          Fetch the next symbol from the input expression string.
(package private)  void parse(java.io.StreamTokenizer st)
          Parse the input expression string, returns the root expression node of the operator-precedence parse tree.
static Symbol toSymbol(java.lang.String s)
          Convert a string to a symbol.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enode

public ExprNode enode
The root expression node generated by parsing the expression string.

symQueue

public java.util.Vector symQueue
The symbol queue created for operator-precedence parsing.

symStack

public java.util.Stack symStack
The operator, expression node stack created for operator-precedence parsing.
Constructor Detail

Expression

public Expression()
Construct an empty expression.

Expression

public Expression(java.lang.String expr)
           throws ExpressionParseException
Construct an expression by a string representation.
Method Detail

appendSymbol

public boolean appendSymbol(Symbol sym)
                     throws ExpressionParseException
Append a symbol to the end of an expression. Return true if the whole expression is reduced into a single expression node, or the expression is empty.

parse

void parse(java.io.StreamTokenizer st)
     throws java.io.IOException,
            ExpressionParseException
Parse the input expression string, returns the root expression node of the operator-precedence parse tree.

eval

public double eval()
            throws ExpressionEvalException
Evaluate the expression.

toSymbol

public static Symbol toSymbol(java.lang.String s)
Convert a string to a symbol.

nextSymbol

public static Symbol nextSymbol(java.io.StreamTokenizer st)
                         throws java.io.IOException,
                                ExpressionParseException
Fetch the next symbol from the input expression string.

getErrMsg

public java.lang.String getErrMsg()
Return a string indicates where the parsing error occurs.