KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > djep > Diff


1 /* @author rich
2  * Created on 04-Jul-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.djep;
9
10 import java.util.Stack JavaDoc;
11
12 import org.lsmp.djep.xjep.*;
13 import org.nfunk.jep.*;
14 import org.nfunk.jep.function.*;
15
16
17 /**
18    * The diff(f,x) opperator.
19    */

20   public class Diff extends PostfixMathCommand implements CommandVisitorI,SpecialEvaluationI
21   {
22       public Diff() {
23           super();
24           numberOfParameters = 2;
25       }
26     
27   /**
28    * Should never be evaluated!
29    * @throws ParseException if called by evaluator.
30    */

31     public void run(Stack JavaDoc inStack) throws ParseException
32     {
33         throw new ParseException("Cannot evaluate the diff function. ");
34     }
35
36     public Object JavaDoc evaluate(Node node,Object JavaDoc data,ParserVisitor pv,Stack JavaDoc inStack) throws ParseException
37     {
38         throw new ParseException("Cannot evaluate the diff function. ");
39     }
40   /**
41    * Process the differentiation specified by node.
42    * Defines process in
43    * @see CommandVisitorI
44    */

45   public Node process(Node node,Node children[],XJep xjep) throws ParseException
46   {
47       Node lhs = children[0];
48       Node rhs = children[1];
49       if(!xjep.getTreeUtils().isVariable(rhs) )
50       {
51         throw new ParseException("Format should be diff(f,x) where x is a variables and 1,2 are constants");
52       }
53       ASTVarNode var;
54       try
55       {
56 // lhs = (Node) node.jjtGetChild(0);
57
var = (ASTVarNode) rhs;
58       }
59       catch(ClassCastException JavaDoc e)
60       { throw new ParseException("Format should be diff(f,x) where x is a variables and 1,2 are constants"); }
61             
62       return ((DJep) xjep).differentiate(lhs,var.getName());
63   }
64 } /* end class Diff */
65
Popular Tags