public class MacroFunction extends PostfixMathCommand
XJepI jep = new XJep();
j.addFunction("zap",new MacroFunction("zap",1,"x*(x-1)/2",j));
Node node = j.parse("zap(10)");
System.out.println(j.evaluate(node)); // print 45
The names of the variables used inside the function depends on the number of arguments:
curNumberOfParameters, numberOfParameters| Constructor and Description |
|---|
MacroFunction(java.lang.String inName,
int nargs,
java.lang.String expression,
XJep jep)
Create a function specified by a string.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getName() |
Node |
getTopNode() |
void |
run(java.util.Stack stack)
Calculates the value of the expression.
|
checkNumberOfParameters, checkStack, getNumberOfParameters, setCurNumberOfParameterspublic MacroFunction(java.lang.String inName,
int nargs,
java.lang.String expression,
XJep jep)
throws java.lang.IllegalArgumentException,
ParseException
inName - name of functionnargs - number of argumentsexpression - a string representing the expression.jep - a reference to main XJep object.java.lang.IllegalArgumentExceptionParseExceptionpublic java.lang.String getName()
public Node getTopNode()
public void run(java.util.Stack stack)
throws ParseException
run in interface PostfixMathCommandIrun in class PostfixMathCommandParseException - if run.http://www.singularsys.com/jep Copyright © 2007 Singular Systems