org.lsmp.djep.xjep
Class MacroFunction
java.lang.Object
org.nfunk.jep.function.PostfixMathCommand
org.lsmp.djep.xjep.MacroFunction
- All Implemented Interfaces:
- PostfixMathCommandI
public class MacroFunction
- extends PostfixMathCommand
A function specified by a string.
For example
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:
- One argument variable must be x: new MacroFunction("sec",1,"1/cos(x)",j)
- Two arguments variables must be x or y: new MacroFunction("myPower",2,"x^y",j)
- Three or more arguments variables must be x1, x2, x3,...: new MacroFunction("add3",3,"x1+x2+x3",j)
- Author:
- R Morris.
Created on 18-Jun-2003
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MacroFunction
public MacroFunction(String inName,
int nargs,
String expression,
XJep jep)
throws IllegalArgumentException,
ParseException
- Create a function specified by a string.
For example new MacroFunction("sec",1,"1/cos(x)",tu) creates the function for sec.
Variable names must be x,y for 1 or 2 variables or x1,x2,x3,.. for 3 or more variables.
- Parameters:
inName - name of functionnargs - number of argumentsexpression - a string representing the expression.jep - a reference to main XJep object.
- Throws:
IllegalArgumentException
ParseException
getName
public String getName()
getTopNode
public Node getTopNode()
run
public void run(Stack stack)
throws ParseException
- Calculates the value of the expression.
- Specified by:
run in interface PostfixMathCommandI- Overrides:
run in class PostfixMathCommand
- Throws:
ParseException - if run.
Copyright © 2014. All rights reserved.