1 8 package org.lsmp.djep.djep; 9 10 import java.util.Stack ; 11 12 import org.lsmp.djep.xjep.*; 13 import org.nfunk.jep.*; 14 import org.nfunk.jep.function.*; 15 16 17 20 public class Diff extends PostfixMathCommand implements CommandVisitorI,SpecialEvaluationI 21 { 22 public Diff() { 23 super(); 24 numberOfParameters = 2; 25 } 26 27 31 public void run(Stack inStack) throws ParseException 32 { 33 throw new ParseException("Cannot evaluate the diff function. "); 34 } 35 36 public Object evaluate(Node node,Object data,ParserVisitor pv,Stack inStack) throws ParseException 37 { 38 throw new ParseException("Cannot evaluate the diff function. "); 39 } 40 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 var = (ASTVarNode) rhs; 58 } 59 catch(ClassCastException 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 } 65 | Popular Tags |