Home Assignments 1 for Programming Theory (TDDA 43)

advertisement
Home Assignments 1
for Programming Theory (TDDA 43)
Deadline: Wednesday week 17 (22 April 2009) at noon.
Provide explanations to justify how and why your solutions work. Put your
solutions, addressed to Jonas Wallgren, in the “Post till IDA” slot at Café
Java. Keep a copy of your solutions for the homework reporting session (Friday week 17).
The numbers in parentheses refer to the old version of our textbook.
A. Exercise 1.14 (1.13) from the textbook. (The meaning of an expression
obtained from a by means of a textual substitution expressed as the meaning
of a in an updated state.)
Hints: Make sure you understand the section on textual substitutions
(p. 18 (16) of the textbook). Use structural induction.
B. Extend the language While with the statement repeat S until b. Assume that its meaning is as in Pascal.1 Define natural and structural operational semantics for this statement (It is not allowed to rely on the existence
of a while statement in the language.)
C. (Optional!) Modify the proof of Theorem 2.26 and Lemmas 2.28, 2.27
(equivalence of the natural and structural semantics of While) so that it
applies to While extended with the repeat statement.
D. Exercise 3.4 from the textbook. (Extend While with the statement
random(x) . . . ).
Hint: To discuss whether random(x) is superfluous, try to find a way
to construct a statement S of While extended with the or construct, such
that S is semantically equivalent to random(x). Use exercise 3.3 as a hint.
Consider the SOS semantics, as a more precise one.
E. Exercise 3.15 (2.45) from the book. (Add call by value arguments to
the language Proc; modify its natural operational semantics to describe this
extension.) Hints: answer the following questions.
1
The execution of this statement consists of repetitively executing S. If b is true after
completing S then the execution ends. In Ada the statement corresponds to loop S exit
when b; end loop;
1
1. In which environment should the arguments a1 , a2 be evaluated?
2. In which environment should the procedure body S be executed? What
should be the store at the beginning of this execution?
3. How should the formal parameters x1 , x2 be treated in this environment?
It may be convenient to begin with call by reference (by variable) arguments.
Your answers may be in Swedish or English. It is allowed to discuss the
exercises with others, but you are supposed to solve each exercise individually.
It is absolutely not allowed to copy solutions from others.
The maximal marks for the problems A, B, C, D and E are, respectively,
3, 2, 3, 3 and 6. To pass you need at least 8 points, including 1p for A, 1p
for B, 0p for C, 1p for D and 2p for E.
2
Download