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 45The names of the variables used inside the function depends on the number of arguments:
Constructor and Description |
---|
MacroFunction(String inName,
int nargs,
String expression,
XJep jep)
Create a function specified by a string.
|
Modifier and Type | Method and Description |
---|---|
String |
getName() |
Node |
getTopNode() |
void |
run(Stack stack)
Calculates the value of the expression.
|
checkNumberOfParameters, getNumberOfParameters, setCurNumberOfParameters
public MacroFunction(String inName, int nargs, String expression, XJep jep) throws IllegalArgumentException, ParseException
inName
- name of functionnargs
- number of argumentsexpression
- a string representing the expression.jep
- a reference to main XJep object.IllegalArgumentException
ParseException
public String getName()
public Node getTopNode()
public void run(Stack stack) throws ParseException
run
in interface PostfixMathCommandI
run
in class PostfixMathCommand
ParseException
- if run.Jas4pp 1.5 © Java Analysis Studio for Particle Physics