1 8 package org.nfunk.jep.function; 9 10 import org.nfunk.jep.*; 11 import java.util.Stack ; 12 20 public class Assign extends PostfixMathCommand implements SpecialEvaluationI { 21 22 public Assign() { 23 super(); 24 numberOfParameters = 2; 25 } 26 27 30 public Object evaluate(Node node,Object data,ParserVisitor pv,Stack inStack) throws ParseException 31 { 32 if(node.jjtGetNumChildren()!=2) 33 throw new ParseException("Assignment opperator must have 2 operators."); 34 35 node.jjtGetChild(1).jjtAccept(pv,data); 37 checkStack(inStack); Object rhsVal = inStack.peek(); 39 40 Node lhsNode = node.jjtGetChild(0); 42 if(lhsNode instanceof ASTVarNode) 43 { 44 ASTVarNode vn = (ASTVarNode) lhsNode; 45 Variable var = vn.getVar(); 46 var.setValue(rhsVal); 47 return rhsVal; 48 } 49 throw new ParseException("Assignment should have a variable for the lhs."); 50 } 51 } 52 | Popular Tags |