AppendixSolutions to the Exercises
A.1. Introduction to language semantics
Solution to exercise 2.1
1)
2) The evaluation of the sequence of definitions d =[var z = 2;let x =8; var y = 5;let x =3;] leads to the state etat0 as follows:
There are several sequences of definitions, which leadto state etat0 . For example, in the sequence d, the definition let x =8may be replaced by let x =!z +6 since, in state ([(z, rz)], [(rz, 2)]), the expression !z +6 is evaluated as 8.
3) Let us develop this expression as follows:
4) In state etat0, the evaluation of the expression !x triggers an error, as x is not a mutable variable in Env0; the evaluation of y + x triggers an error, as y is evaluated as a reference to which addition cannot be applied, and the evaluation of the identifier w triggers an error, as it is unbound in Env0.
5) By applying the rules given in the statement, we obtain the following states and environments:
6) Applying the rules in the statement, we obtain the following results:
Solution to exercise 2.2
1) Depending on the order in which expressions e1 and e2 are evaluated ...
Get Concepts and Semantics of Programming Languages 1 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.