org.lsmp.djep.xjep
Class MacroFunction

java.lang.Object
  extended by org.nfunk.jep.function.PostfixMathCommand
      extended by 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:

Author:
R Morris. Created on 18-Jun-2003

Field Summary
 
Fields inherited from class org.nfunk.jep.function.PostfixMathCommand
curNumberOfParameters, numberOfParameters
 
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 org.nfunk.jep.function.PostfixMathCommand
checkNumberOfParameters, checkStack, getNumberOfParameters, setCurNumberOfParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 function
nargs - number of arguments
expression - a string representing the expression.
jep - a reference to main XJep object.
Throws:
java.lang.IllegalArgumentException
ParseException
Method Detail

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 © 2007 Singular Systems