Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

36. Let p0 = P{X = 0} and suppose that 0 Answered: 1 week ago

Answered: 1 week ago