public class MacroFunction extends PostfixMathCommand implements JepComponent
MacroFunction fact = new MacroFunction( "fact",new String[]{"x"}, "if(x>1,x*fact(x-1),1)"); jep.addFunction("fact",fact); fact.init(jep); Node n = jep.parse("fact(5)");
Modifier and Type | Field and Description |
---|---|
protected Node |
topNode |
curNumberOfParameters, name, NaN, numberOfParameters
Constructor and Description |
---|
MacroFunction(Jep jep,
java.lang.String funName,
java.lang.String[] parameters,
java.lang.String expression)
Create a macro function with two or more arguments defined by an expression.
|
MacroFunction(Jep jep,
java.lang.String funName,
java.lang.String parameter,
java.lang.String expression)
Create a macro function with a single arguments defined by an expression.
|
MacroFunction(java.lang.String funName,
java.lang.String[] parameters,
java.lang.String expression)
Create a macro function with two or more arguments defined by an expression.
|
Modifier and Type | Method and Description |
---|---|
JepComponent |
getLightWeightInstance()
Returns null
|
java.lang.String[] |
getParameterNames() |
Node |
getTopNode() |
Variable[] |
getVars()
Get the internal variables used, these have specific names like 'fun::x'
|
void |
init(Jep j)
The init method must be called after construction.
|
void |
run(java.util.Stack<java.lang.Object> stack)
Calculates the value of the expression.
|
java.lang.String |
toString() |
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString
protected transient Node topNode
public MacroFunction(Jep jep, java.lang.String funName, java.lang.String[] parameters, java.lang.String expression)
jep
- The jep instancefunName
- name of the functionparameters
- an array of the formal parameter names used by the functionexpression
- public MacroFunction(Jep jep, java.lang.String funName, java.lang.String parameter, java.lang.String expression)
jep
- The jep instancefunName
- name of the functionparameter
- the name of the formal parameter.expression
- public MacroFunction(java.lang.String funName, java.lang.String[] parameters, java.lang.String expression)
init(Jep)
method
must be called after the function is added to the function table, which will recompile the function.funName
- name of the functionparameters
- an array of the formal parameter names used by the functionexpression
- public void init(Jep j)
init
in interface JepComponent
j
- jep instancejava.lang.RuntimeException
- if errors compiling the expression.public void run(java.util.Stack<java.lang.Object> stack) throws EvaluationException
run
in interface PostfixMathCommandI
run
in class PostfixMathCommand
stack
- arguments for functionEvaluationException
- if the calculation cannot be performedpublic Node getTopNode()
public java.lang.String[] getParameterNames()
public Variable[] getVars()
public java.lang.String toString()
toString
in class PostfixMathCommand
public JepComponent getLightWeightInstance()
getLightWeightInstance
in interface JepComponent
Copyright © 2018 Singular Systems http://www.singularsys.com/jep