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 fuction 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
 
 
 
| 
Constructor Summary | 
MacroFunction(java.lang.String inName,
              int nargs,
              java.lang.String expression,
              XJep jep)
 
          Create a function specified by a string.
  | 
 
| 
Method Summary | 
 java.lang.String | 
getName()
 
            | 
 Node | 
getTopNode()
 
            | 
 void | 
run(java.util.Stack 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 | 
 
MacroFunction
public MacroFunction(java.lang.String inName,
                     int nargs,
                     java.lang.String expression,
                     XJep jep)
              throws java.lang.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.
getName
public java.lang.String getName()
 
getTopNode
public Node getTopNode()
 
run
public void run(java.util.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.
 
 
http://www.singularsys.com/jep Copyright © 2004 Singular Systems