com.singularsys.jep.misc
Class MacroFunction
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.misc.MacroFunction
- All Implemented Interfaces:
- PostfixMathCommandI, java.io.Serializable
public class MacroFunction
- extends PostfixMathCommand
A function specified by a string.
For example
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)");
- Author:
- R Morris.
- See Also:
- Serialized Form
Constructor Summary |
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. |
MacroFunction(java.lang.String funName,
java.lang.String parameter,
java.lang.String expression)
Create a macro function with a single arguments defined by an expression. |
Method Summary |
java.lang.String |
getName()
|
java.lang.String[] |
getParameterNames()
|
Node |
getTopNode()
|
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
topNode
protected transient Node topNode
MacroFunction
public 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.
- Parameters:
funName
- name of the functionparameters
- an array of the formal parameter names used by the functionexpression
-
MacroFunction
public MacroFunction(java.lang.String funName,
java.lang.String parameter,
java.lang.String expression)
- Create a macro function with a single arguments defined by an expression.
- Parameters:
funName
- name of the functionparameter
- the name of the formal parameter.expression
-
init
public void init(Jep j)
throws ParseException
- The init method must be called after construction.
- Parameters:
j
-
- Throws:
ParseException
- if the expression fails to parse
run
public void run(java.util.Stack<java.lang.Object> stack)
throws EvaluationException
- Calculates the value of the expression.
- Throws:
EvaluationException
getName
public java.lang.String getName()
getTopNode
public Node getTopNode()
getParameterNames
public java.lang.String[] getParameterNames()
Copyright © 2008 Singular Systems http://www.singularsys.com/jep