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(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, checkStack, getNumberOfParameters, setCurNumberOfParameterspublic 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.IllegalArgumentExceptionParseExceptionpublic String getName()
public Node getTopNode()
public void run(Stack stack) throws ParseException
run in interface PostfixMathCommandIrun in class PostfixMathCommandParseException - if run.Copyright © 2018. All rights reserved.