Question: Revise the function freevars : expr -> string list to work for the language as extended in Exercise 2.1. Note that the example expression in

Revise the function freevars : expr -> string list to work for the language as extended in Exercise 2.1. Note that the example expression in the beginning of Exercise 2.1 has no free variables, but let x1 = x1+7 in x1+8 end has the free variable x1, because the variable x1 is bound only in the body (x1+8), not in the right-hand side (x1+7), of its own binding. There are programming languages where a variable can be used in the right-hand side of its own binding, but ours is not such a language.

Exercise 2.1:

Extend the expression language expr from Intcomp1.fs with multiple sequential let-bindings, such as this (in concrete syntax):

let x1 = 5+7 x2 = x1*2 in x1+x2 end

To evaluate this, the right-hand side expression 5+7 must be evaluated and bound to x1, and then x1*2 must be evaluated and bound to x2, after which the let-body x1+x2 is evaluated. The new abstract syntax for expr might be

so that the Let constructor takes a list of bindings, where a binding is a pair of a variable name and an expression. The example above would be represented as: Let ([("x1", ...); ("x2", ...)], Prim("+", Var "x1", Var "x2")) Revise the eval interpreter from Intcomp1.fs to work for the expr language extended with multiple sequential let-bindings.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!