Track three environments

An interpreter evaluates integer expression trees. Num returns its integer, Var looks up a name, and Add and Mul perform ordinary arithmetic. A Let evaluates its initializer in the incoming environment, copies that environment, installs the local binding in the copy, and evaluates its body there.


The caller's environment initially binds p to 7. Evaluate this tree:


Python
Let("p", Num(10),
    Add(Let("p", Num(4),
            Mul(Var("p"), Num(3))),
        Var("p")))


Report the inner Let result, the whole expression result, and the caller's value of p after evaluation. All three are dimensionless integer values; enter exact integers with zero decimal places.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Programming Language Design and Construction Questions: