public class JEP extends Object implements Serializable
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.
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addComplex()
Call this function if you want to parse expressions which involve
complex numbers.
|
void |
addConstant(String name,
Object value)
Adds a constant.
|
void |
addFunction(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.
|
Double |
addVariable(String name,
double value)
Adds a new variable to the parser, or updates the value of an
existing variable.
|
Complex |
addVariable(String name,
double re,
double im)
Adds a new complex variable to the parser, or updates the value of an
existing variable.
|
void |
addVariable(String name,
Object object)
Adds a new variable to the parser as an object, or updates the value of an
existing variable.
|
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.
|
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.
|
Object |
getValueAsObject()
Evaluates and returns the value of the expression as an object.
|
Variable |
getVar(String name)
Gets the object representing the variable with a given name.
|
Object |
getVarValue(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(String expression)
Parses an expression.
|
Node |
parseExpression(String expression_in)
Parses the expression.
|
Object |
removeFunction(String name)
Removes a function from the parser.
|
Object |
removeVariable(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.
|
void |
setVarValue(String name,
Object val)
Sets the value of a variable.
|
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.public void initSymTab()
public void initFunTab()
public void addStandardFunctions()
public void addStandardConstants()
public void addComplex()
public void addFunction(String functionName, PostfixMathCommandI function)
functionName
- The name of the functionfunction
- The function object that is used for evaluating the
functionpublic void addConstant(String name, Object value)
public Double addVariable(String name, double value)
name
- Name of the variable to be addedvalue
- Initial value or new value for the variablepublic Complex addVariable(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 variablepublic void addVariable(String name, Object object)
name
- Name of the variable to be addedobject
- Initial value or new value for the variablepublic Object removeVariable(String name)
null
is
returned.public Object getVarValue(String name)
name
- name of the variable.public void setVarValue(String name, Object val)
name
- name of the variable.val
- the initial value of the variable.NullPointerException
- if the variable has not been previously created
with addVariable(String,Object)
first.public Variable getVar(String name)
name
- the name of the variable to find.public Object removeFunction(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(String expression_in)
errorList
member. Errors can be
obtained through getErrorInfo()
.expression_in
- The input expression stringnull
otherwisepublic Node parse(String expression) throws ParseException
evaluate
method rather than getValueAsObject.expression
- represented as a string.ParseException
public 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 evaluatedRuntimeException
- could potentially be thrown.public double getValue()
getComplexValue()
public Complex getComplexValue()
public Object getValueAsObject()
public boolean hasError()
true
if an error occurred during the most
recent action (parsing or evaluation).public String getErrorInfo()
public Node getTopNode()
public SymbolTable getSymbolTable()
public FunctionTable getFunctionTable()
public EvaluatorVisitor getEvaluatorVisitor()
public NumberFactory getNumberFactory()
public OperatorSet getOperatorSet()
public Parser getParser()
Jas4pp 1.5 © Java Analysis Studio for Particle Physics