import java.util.*; public class Evaluator extends ExpressionVisitor { private Stack values = new Stack(); public void visitIntExp(IntExp e) { values.push( e.getValue() ); } public void visitAddExp(AddExp e) { e.getE1().accept(this); int x1 = values.pop(); e.getE2().accept(this); int x2 = values.pop(); values.push(x1+x2); } public int finalValue() { return values.pop(); } }