CS 217: Programming Languages

Written Assignment #2

Assigned on Wednesday, 2/19.
Due in class on Monday, 2/24.


From your textbook (Scott), turn in:

Review Question 6.14

Exercises 6.27

Also, answer the following:

1. The Pascal if statement has the syntax

if Boolean_expression then statement else statement

whereas the Ada if is

if Boolean_expression then statement else statement end if

Comment on the relative merits of having an explicit terminator to the statement, such as the end if of Ada.

2. Dynamic type binding is closely related to heap variables. Explain this relationship.

3. Should an optimizing compiler for C or C++ be allowed to change the order of subexpressions in a Boolean expression? Why or why not?

4. Consider the following ALGOL 60-style for statement:

for i := j + 1 step i * j until 3 * j do j := j + 1

Assume that the initial value of j is 1. List the sequence of values for the variable i used, assuming the following semantics:

(a) All expressions are evaluated once at the loop entry.
(b) All expressions are evaluated before each iteration.
(c) step expressions are evaluated once at loop entry, and until expressions are evaluated before each iteration.
(d) until expressions are evaluated once at loop entry, and step expressions are evaluated before each iteration, just after the loop counter is incremented.