CS 334
Programming Languages
Spring 2000

Assignment 9
Due Friday, 5/5/2000


  1. Variables can be said to have both L-values and R-values, where the L-value of a variable is the location it denotes and the R-value is the value stored in that location. The environment keeps track of the locations corresponding to variables, while the store (or state) keeps track of the values stored in locations. Recall from an earlier problem set that the semantics of the assignment statement for most programming languages is usually given as follows: When V := E is executed, the L-value of V is first obtained from the environment (call it l), then the expression E is evaluated, and that resulting value is stored in the location l. While side-effects can create great confusion in terms of what the result of an assignment statement will be; in this problem, side-effects are not the problem!

    a) Describe in detail the effect of executing the Pascal assignment

    	a[a[i]] := a[i] + 1
    
    b) Is it always the case (in Pascal) that the value of L after executing assignment L := E is equal to the value of E before executing the command? I.e. if you execute the following code:
    	write(E); L := E; writeln(L);
    
    will the two values printed always be the same? For the purposes of this problem assume that the evaluation of E has no side effects. Hint : consider the assignment in part (a) with i = 2, a[2] = 2, a[3] = 0.

    c) What does this tell you about the validity of the axiomatic rule for assignment,{P [E / L]} L := E {P}, (e.g., if L = a[a[i]], E = a[i] + 1, and P is a[a[i]] = 3)? Suggest a restriction which makes it valid.