|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.nfunk.jep.JEP
public class JEP
The JEP class is the main interface with which the user should interact. It contains all necessary methods to parse and evaluate expressions.
The most important methods are parseExpression(String), for parsing the mathematical expression, and getValue() for obtaining the value of the expression.
Visit http://www.singularsys.com/jep for the newest version of JEP, and complete documentation.
Field Summary | |
---|---|
protected boolean |
allowAssignment
Allow undeclared variables option |
protected boolean |
allowUndeclared
Allow undeclared variables option |
protected java.util.Vector |
errorList
Error List |
protected EvaluatorVisitor |
ev
Evaluator |
protected FunctionTable |
funTab
Function Table |
protected boolean |
implicitMul
Implicit multiplication option |
protected NumberFactory |
numberFactory
Number factory |
protected OperatorSet |
opSet
OperatorSet |
protected Parser |
parser
The parser object |
protected SymbolTable |
symTab
Symbol Table |
Constructor Summary | |
---|---|
|
JEP()
Creates a new JEP instance with the default settings. |
|
JEP(boolean traverse_in,
boolean allowUndeclared_in,
boolean implicitMul_in,
NumberFactory numberFactory_in)
Creates a new JEP instance with custom settings. |
protected |
JEP(JEP j)
This constructor copies the SymbolTable and other components of the arguments to the new instance. |
Method Summary | |
---|---|
void |
addComplex()
Call this function if you want to parse expressions which involve complex numbers. |
void |
addConstant(java.lang.String name,
java.lang.Object value)
Adds a constant. |
void |
addFunction(java.lang.String functionName,
PostfixMathCommandI 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. |
Complex |
addVariable(java.lang.String name,
double re,
double im)
Adds a new complex variable to the parser, or updates the value of an existing variable. |
void |
addVariable(java.lang.String name,
java.lang.Object object)
Adds a new variable to the parser as an object, or updates the value of an existing variable. |
java.lang.Object |
evaluate(Node node)
Evaluate an expression. |
boolean |
getAllowAssignment()
Whether assignment equation y=x+1 equations are allowed. |
boolean |
getAllowUndeclared()
Returns the value of the allowUndeclared option. |
Complex |
getComplexValue()
Evaluates and returns the value of the expression as a complex number. |
java.lang.String |
getErrorInfo()
Reports information on the errors that occurred during the most recent action. |
EvaluatorVisitor |
getEvaluatorVisitor()
Returns the EvaluatorVisitor |
FunctionTable |
getFunctionTable()
Returns the function table (the list of all functions that the parser recognizes). |
boolean |
getImplicitMul()
Returns the value of the implicit multiplication option. |
NumberFactory |
getNumberFactory()
Returns the number factory. |
OperatorSet |
getOperatorSet()
Returns the operator set. |
Parser |
getParser()
Returns the parse object. |
SymbolTable |
getSymbolTable()
Returns the symbol table (the list of all variables that the parser recognizes). |
Node |
getTopNode()
Returns the top node of the expression tree. |
boolean |
getTraverse()
Returns the value of the traverse option. |
double |
getValue()
Evaluates and returns the value of the expression as a double number. |
java.lang.Object |
getValueAsObject()
Evaluates and returns the value of the expression as an object. |
Variable |
getVar(java.lang.String name)
Gets the object representing the variable with a given name. |
java.lang.Object |
getVarValue(java.lang.String name)
Returns the value of the variable with given name. |
boolean |
hasError()
Returns true if an error occurred during the most recent action (parsing or evaluation). |
void |
initFunTab()
Creates a new FunctionTable object as funTab. |
void |
initSymTab()
Creates a new SymbolTable object as symTab. |
Node |
parse(java.lang.String expression)
Parses an expression. |
Node |
parseExpression(java.lang.String expression_in)
Parses the expression. |
java.lang.Object |
removeFunction(java.lang.String name)
Removes a function from the parser. |
java.lang.Object |
removeVariable(java.lang.String name)
Removes a variable from the parser. |
void |
setAllowAssignment(boolean value)
Sets whether assignment equations like y=x+1 are allowed. |
void |
setAllowUndeclared(boolean value)
Sets the value for the undeclared variables option. |
void |
setImplicitMul(boolean value)
Sets the value of the implicit multiplication option. |
void |
setTraverse(boolean value)
Sets the value of the traverse option. setTraverse is useful for debugging purposes. |
void |
setVarValue(java.lang.String name,
java.lang.Object val)
Sets the value of a variable. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean allowUndeclared
protected boolean allowAssignment
protected boolean implicitMul
protected SymbolTable symTab
protected FunctionTable funTab
protected java.util.Vector errorList
protected Parser parser
protected EvaluatorVisitor ev
protected NumberFactory numberFactory
protected OperatorSet opSet
Constructor Detail |
---|
public JEP()
Traverse = false
Allow undeclared variables = false
Implicit multiplication = false
Number Factory = DoubleNumberFactory
public JEP(boolean traverse_in, boolean allowUndeclared_in, boolean implicitMul_in, NumberFactory numberFactory_in)
traverse_in
- The traverse option.allowUndeclared_in
- The "allow undeclared variables" option.implicitMul_in
- The implicit multiplication option.numberFactory_in
- The number factory to be used.protected JEP(JEP j)
Method Detail |
---|
public void initSymTab()
public void initFunTab()
public void addStandardFunctions()
public void addStandardConstants()
public void addComplex()
public void addFunction(java.lang.String functionName, PostfixMathCommandI function)
functionName
- The name of the functionfunction
- The function object that is used for evaluating the
functionpublic void addConstant(java.lang.String name, java.lang.Object value)
public java.lang.Double addVariable(java.lang.String name, double value)
name
- Name of the variable to be addedvalue
- Initial value or new value for the variable
public Complex addVariable(java.lang.String name, double re, double im)
name
- Name of the variable to be addedre
- Initial real value or new real value for the variableim
- Initial imaginary value or new imaginary value for the variable
public void addVariable(java.lang.String name, java.lang.Object object)
name
- Name of the variable to be addedobject
- Initial value or new value for the variablepublic java.lang.Object removeVariable(java.lang.String name)
null
is
returned.public java.lang.Object getVarValue(java.lang.String name)
name
- name of the variable.
public void setVarValue(java.lang.String name, java.lang.Object val)
name
- name of the variable.val
- the initial value of the variable.
java.lang.NullPointerException
- if the variable has not been previously created
with addVariable(String,Object)
first.public Variable getVar(java.lang.String name)
name
- the name of the variable to find.
public java.lang.Object removeFunction(java.lang.String name)
null
is returned.public void setTraverse(boolean value)
The default value is false.
value
- The boolean traversal option.public boolean getTraverse()
public void setImplicitMul(boolean value)
"1 2"is valid and is interpreted as
"1*2".
The default value is false.
value
- The boolean implicit multiplication option.public boolean getImplicitMul()
public void setAllowUndeclared(boolean value)
If this option is set to false, variables that were not previously added to JEP will produce an error while parsing.
The default value is false.
value
- The boolean option for allowing undeclared variables.public boolean getAllowUndeclared()
public void setAllowAssignment(boolean value)
public boolean getAllowAssignment()
public Node parseExpression(java.lang.String expression_in)
errorList
member. Errors can be
obtained through getErrorInfo()
.
expression_in
- The input expression string
null
otherwisepublic Node parse(java.lang.String expression) throws ParseException
evaluate
method rather than getValueAsObject.
expression
- represented as a string.
ParseException
public java.lang.Object evaluate(Node node) throws ParseException
parse
rather than parseExpression
.
node
- the top node of the tree representing the expression.
ParseException
- if for some reason the expression could not be evaluated
java.lang.RuntimeException
- could potentially be thrown.public double getValue()
getComplexValue()
public Complex getComplexValue()
public java.lang.Object getValueAsObject()
public boolean hasError()
true
if an error occurred during the most
recent action (parsing or evaluation).public java.lang.String getErrorInfo()
public Node getTopNode()
public SymbolTable getSymbolTable()
public FunctionTable getFunctionTable()
public EvaluatorVisitor getEvaluatorVisitor()
public NumberFactory getNumberFactory()
public OperatorSet getOperatorSet()
public Parser getParser()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |