1 8 package org.lsmp.djep.matrixJep; 9 10 import org.lsmp.djep.djep.*; 11 import org.lsmp.djep.djep.diffRules.*; 12 import org.nfunk.jep.*; 13 import org.nfunk.jep.function.*; 14 import org.lsmp.djep.vectorJep.values.*; 15 import org.lsmp.djep.vectorJep.function.*; 16 import org.lsmp.djep.xjep.*; 17 import org.lsmp.djep.matrixJep.function.*; 18 import org.lsmp.djep.matrixJep.nodeTypes.*; 19 25 public class MatrixJep extends DJep { 26 27 protected MatrixPreprocessor dec = new MatrixPreprocessor(); 28 protected MatrixVariableFactory mvf = new MatrixVariableFactory(); 29 protected MatrixEvaluator mev = new MatrixEvaluator(); 30 31 public MatrixJep() { 32 super(); 33 nf = new MatrixNodeFactory(); 34 symTab = new DSymbolTable(mvf); 35 opSet = new MatrixOperatorSet(); 36 this.parser.setInitialTokenManagerState(Parser.NO_DOT_IN_IDENTIFIERS); 37 38 Operator tens = ((MatrixOperatorSet) opSet).getMList(); 39 pv.addSpecialRule(tens,(PrintVisitor.PrintRulesI) tens.getPFMC()); 40 addDiffRule(new PassThroughDiffRule(tens.getName(),tens.getPFMC())); 41 Operator cross = ((MatrixOperatorSet) opSet).getCross(); 42 addDiffRule(new MultiplyDiffRule(cross.getName(),cross)); 43 Operator dot = ((MatrixOperatorSet) opSet).getDot(); 44 addDiffRule(new MultiplyDiffRule(dot.getName(),dot)); 45 } 46 47 public void addStandardFunctions() 48 { 49 super.addStandardFunctions(); 50 this.getFunctionTable().remove("if"); 51 addFunction("pow",new Power()); 52 addFunction("if",new MIf()); 53 addFunction("ele",new Ele()); 54 } 55 56 59 public Object evaluate(Node node) throws ParseException 60 { 61 Object res = mev.evaluate((MatrixNodeI) node,this); 62 if(res instanceof Scaler) 63 return ((Scaler) res).getEle(0); 64 else 65 return res; 66 } 67 68 69 public Object evaluateRaw(Node node) throws ParseException 70 { 71 Object res = mev.evaluate((MatrixNodeI) node,this); 72 return res; 73 } 74 75 76 public Node preprocess(Node node) throws ParseException 77 { 78 return dec.preprocess(node,this); 79 } 80 81 84 public Object getValueAsObject() { 85 try 86 { 87 Object res = mev.evaluate((MatrixNodeI) getTopNode(),this); 88 if(res instanceof Scaler) 89 return ((Scaler) res).getEle(0); 90 else 91 return res; 92 } 93 catch(Exception e) 94 { 95 this.errorList.addElement("Error during evaluation:"); 96 this.errorList.addElement(e.getMessage()); 97 return null; 98 } 99 } 100 } 101 | Popular Tags |