
import java.util.*;

public class Evaluator extends ExpressionVisitor {

  private Stack<Integer> values = new Stack<Integer>();

  void visitIntExp(IntExp e) {

    values.push( e.value );

  }

  void visitAddExp(AddExp e) {

    e.e1.accept(this);

    int x = values.pop();

    e.e2.accept(this);

    int y = values.pop();

    values.push(x+y);

  }

  public int finalValue() {

    return values.pop();

  }

}
