1 9 10 package org.lsmp.djep.xjep; 11 12 import org.nfunk.jep.*; 13 14 30 public class XEvaluatorVisitor extends EvaluatorVisitor { 31 32 33 public XEvaluatorVisitor() { 34 } 38 39 43 public Object visit(ASTVarNode node, Object data) throws ParseException { 44 45 Variable var = node.getVar(); 46 if (var == null) { 47 String message = "Could not evaluate " + node.getName() + ": "; 48 throw new ParseException(message + " variable not set"); 49 } 50 51 if(var.hasValidValue()) 52 { 53 stack.push(var.getValue()); 54 } 55 else if(var instanceof XVariable) 56 { 57 Node equation = ((XVariable) var).getEquation(); 58 if(equation==null) 59 throw new ParseException("Cannot find value of "+var.getName()+" no equation."); 60 equation.jjtAccept(this,data); 61 var.setValue(stack.peek()); 62 } 63 else 64 { 65 throw new ParseException("Could not evaluate " + node.getName() + ": value not set"); 66 } 67 68 return data; 69 } 70 } 71 | Popular Tags |