|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.nfunk.jep.JEP
The JEP class is the main interface with which the user should interact. It contains all neccessary 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://jep.sourceforge.net/ for the newest version of JEP, and complete documentation.
Field Summary | |
protected boolean |
allowUndeclared
Allow undeclared variables option |
protected java.util.Vector |
errorList
Error List |
protected FunctionTable |
funTab
Function Table |
protected boolean |
implicitMul
Implicit multiplication option |
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. |
Method Summary | |
void |
addComplex()
Call this function if you want to parse expressions which involve complex numbers. |
Complex |
addComplexVariable(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 |
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. |
void |
addVariableAsObject(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. |
Complex |
getComplexValue()
Evaluates and returns the value of the expression as a complex number. |
java.lang.String |
getErrorInfo()
Reports information on the errors that occured during the most recent action. |
NumberFactory |
getNumberFactory()
Returns the number factory. |
SymbolTable |
getSymbolTable()
Returns the symbol table (the list of all variables that the parser recognises). |
Node |
getTopNode()
Returns the top node of the expression tree. |
double |
getValue()
Evaluates and returns the value of the expression. |
java.lang.Object |
getValueAsObject()
Evaluates and returns the value of the expression as an object. |
boolean |
hasError()
Returns true if an error occured 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. |
void |
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 |
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. |
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 implicitMul
protected SymbolTable symTab
protected FunctionTable funTab
protected java.util.Vector errorList
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.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 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 addComplexVariable(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 variable
public void addVariableAsObject(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 removeFunction(java.lang.String name)
null
is returned.public void setTraverse(boolean value)
The default value is false.
value
- The boolean traversal option.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 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 void parseExpression(java.lang.String expression_in)
errorList
member.
expression_in
- The input expression stringpublic double getValue()
public Complex getComplexValue()
public java.lang.Object getValueAsObject()
public boolean hasError()
true
if an error occured during the most
recent action (parsing or evaluation).public java.lang.String getErrorInfo()
public Node getTopNode()
public SymbolTable getSymbolTable()
public NumberFactory getNumberFactory()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |