org.cheffo.jeplite
Class JEP

java.lang.Object
  |
  +--org.cheffo.jeplite.JEP

public class JEP
extends java.lang.Object


Constructor Summary
JEP()
           
 
Method Summary
 void addFunction(java.lang.String functionName, java.lang.Object function)
          Adds a new function to the parser.
 void addStandardConstants()
          Adds the constants pi and e to the parser.
 void addStandardFunctions()
          Adds the standard functions to the parser.
 java.lang.Double addVariable(java.lang.String name, double value)
          Adds a new variable to the parser, or updates the value of an existing variable.
 java.lang.String getErrorInfo()
          Reports information on the error in the expression
 SimpleNode getTopNode()
           
 double getValue()
          Evaluates and returns the value of the expression.
 double getValue(DoubleStack evalStack)
           
 ASTVarNode getVarNode(java.lang.String var)
           
 boolean hasError()
          Reports whether there is an error in the expression
 void initFunTab()
          Initializes the function table
 void initSymTab()
          Initializes the symbol table
 void parseExpression(java.lang.String expression_in)
          Parses the expression
 void setVarNode(java.lang.String var, ASTVarNode node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JEP

public JEP()
Method Detail

initSymTab

public void initSymTab()
Initializes the symbol table


initFunTab

public void initFunTab()
Initializes the function table


addStandardFunctions

public void addStandardFunctions()
Adds the standard functions to the parser. If this function is not called before parsing an expression, functions such as sin() or cos() would produce an "Unrecognized function..." error. In most cases, this method should be called immediately after the JEP object is created.


addStandardConstants

public void addStandardConstants()
Adds the constants pi and e to the parser. As addStandardFunctions(), this method should be called immediatly after the JEP object is created.


addFunction

public void addFunction(java.lang.String functionName,
                        java.lang.Object function)
Adds a new function to the parser. This must be done before parsing an expression so the parser is aware that the new function may be contained in the expression.


addVariable

public java.lang.Double addVariable(java.lang.String name,
                                    double value)
Adds a new variable to the parser, or updates the value of an existing variable. This must be done before parsing an expression so the parser is aware that the new variable may be contained in the expression.

Parameters:
name - Name of the variable to be added
value - Initial value or new value for the variable
Returns:
Double object of the variable

getVarNode

public ASTVarNode getVarNode(java.lang.String var)

setVarNode

public void setVarNode(java.lang.String var,
                       ASTVarNode node)

parseExpression

public void parseExpression(java.lang.String expression_in)
Parses the expression

Parameters:
expression_in - The input expression string

getValue

public double getValue()
                throws ParseException
Evaluates and returns the value of the expression. If the value is complex, the real component of the complex number is returned. To get the complex value, use getComplexValue().

Returns:
The calculated value of the expression. If the value is complex, the real component is returned. If an error occurs during evaluation, 0 is returned.
ParseException

getTopNode

public SimpleNode getTopNode()

getValue

public double getValue(DoubleStack evalStack)
                throws ParseException
ParseException

hasError

public boolean hasError()
Reports whether there is an error in the expression

Returns:
Returns true if the expression has an error

getErrorInfo

public java.lang.String getErrorInfo()
Reports information on the error in the expression

Returns:
Returns a string containing information on the error; null if no error has occured