|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfr.expression4j.core.impl.ExpressionImpl
public class ExpressionImpl
Construct expression relative to the BNF:
expression ::= term additive-op expression | term
additive-op ::= "+" | "-"
term ::= factor multiplicatice-op term | factor
multiplicative-op ::= "*" | "-"
factor ::= (signed-expression "^" factor) | signed-expression
signed-expression ::= additive-op simple-expression | simple-expression
simple-expression ::= complex | real | constant | variable | function | "(" expression ")"
complex ::= real "i"
real ::= real-simple | real-simple "e" signed-integer
real-simple ::= integer | integer "." integer
signed-integer ::= additive-op integer | integer
integer ::= number integer | number
number ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
constant ::= variable
variable ::= letters integer | letters
letters ::= letter letters | letter
letter ::= a - Z
function ::= function-name "(" parameters ")"
function-name ::= variable
parameters ::= expression "," parameters | expression | ""
function-def ::= function-name "(" parameters-def ")=" expression
parameters-def ::= variable "," parameters-def | variable | ""
expr ::= function-def = expression
Valid expression is like:
- f()=2*5+1
- g(x)=2.5*x
- h(x)=-2e-3*(x+1)
- i(x,y)=h(y)*2+sqrt(g(x))
- j(z)=h(2*z+4)-g(h(z))
- ...
How does it work
The parser parse expression and create an expression tree modeling the expression.
Expression is not parsed each time you evaluate it. When evaluate expression
only the tree is used.
g(x)=4*2/2+f(x)
+
/ \
/ f()
/ \ |
* 2 x
/ \
4 2
| Field Summary | |
|---|---|
protected Catalog |
catalog
|
protected ExpressionModel |
expressionModel
|
protected java.util.List |
functionParameters
|
protected java.lang.String |
name
|
protected TreeElement |
rootElement
|
| Constructor Summary | |
|---|---|
ExpressionImpl()
Constructor. |
|
| Method Summary | |
|---|---|
MathematicalElement |
evaluate(OperatorManager operatorManager,
Parameters parameters)
Evaluate the value of the expression. |
MathematicalElement |
evaluate(Parameters parameters)
Evaluate the value of the expression with the default operator manager. |
Catalog |
getCatalog()
return the catalog of the expression. |
ExpressionModel |
getExpressionModel()
Return the expression model associated to the expression. |
java.lang.String |
getName()
Get the name of the function. |
java.util.List |
getParameters()
Get the parameter list associated to the function. |
TreeElement |
getRootElement()
|
static void |
main(java.lang.String[] args)
|
void |
parse(java.lang.String expression,
Catalog catalog,
ExpressionModel model)
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected TreeElement rootElement
protected java.lang.String name
protected java.util.List functionParameters
protected Catalog catalog
protected ExpressionModel expressionModel
| Constructor Detail |
|---|
public ExpressionImpl()
| Method Detail |
|---|
public void parse(java.lang.String expression,
Catalog catalog,
ExpressionModel model)
throws ParsingException
ParsingExceptionpublic Catalog getCatalog()
Expression
getCatalog in interface Expressionnull if no catalog is needed of define.
public MathematicalElement evaluate(OperatorManager operatorManager,
Parameters parameters)
throws EvalException
Expression
evaluate in interface ExpressionoperatorManager - operator manager to use to evaluate expression.parameters - parameters values for evaluating expression.
EvalException - when error occurd (parameter not found ...)
public MathematicalElement evaluate(Parameters parameters)
throws EvalException
Expression
evaluate in interface Expressionparameters - parameters values for evaluating expression.
EvalException - when error occurd (parameter not found ...)public java.lang.String getName()
Expression
getName in interface Expressionpublic java.util.List getParameters()
Expression
getParameters in interface Expressionpublic TreeElement getRootElement()
public java.lang.String toString()
toString in class java.lang.Objectpublic static void main(java.lang.String[] args)
public ExpressionModel getExpressionModel()
Expression
getExpressionModel in interface Expression
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||