/* * For a binary operation, the operation symbol will be considered to process different operation. */ public Object eval(Environment env) { Stringop= operator(); if ("=".equals(op)) { ASTreerightTree= right(); ObjectrightVal= rightTree.eval(env); return computeAssign(env, rightVal); } else { Objectleft= left().eval(env); Objectright= right().eval(env); return computeOp(left, op, right); } }
if语句:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* * For a if statement, condition will eval first to decide whether the if block be executed. */ public Object eval(Environment env) { Objectc= condition().eval(env); if (c instanceof Integer && ((Integer)c).intValue() != FALSE) return thenBlock().eval(env); else { ASTreeb= elseBlock(); if (b == null) return0; else return b.eval(env); } }