University of Virginia, Department of Computer Science
CS655: Programming Languages
Spring 2000
Problem Set 1: Operational Semantics Out: 25 January 2000
Due: Thursday, 3 February in class

Problem set answers may be hand-written. Please make sure your answers are clearly marked and neat enough to be read and understood.

Collaboration Policy Reminder: You are permitted (and encouraged) to discuss these problems with your classmates and sketch out your proposed solutions. What you turn in should be your own work, and you should cite the people you worked with on it.

Warm-up

0. Extending BARK
William H. Fences IV decides that the quickest path to world domination is to build a better BASIC. He suggests extending BARK with the following command:
STOREBLOCK Loc_1 Loc_2 Loc_3
Store the value in Loc_3 in every location between Loc_1 and Loc_2.
(a) Is the informal semantics for STOREBLOCK sufficiently clear? If not, clarify them (with an English description).

(b) Show the operational semantics for STOREBLOCK using the RVM from Lecture 2. See http://www.cs.virginia.edu/~cs655/problem-sets/ps1-rvm.html for a review of the RVM.

Operational Semantics for PostFix using the RVM

In class, we developed an operational semantics for a simple register-based language using a register virtual machine (RVM). In Turbak and Gifford's notes, they developed an operational semantics for a simple stack-based language using a stack-based virtual machine. In both cases, the virtual machine and programming language were similar enough that the operational semantics were relatively straightforward. In this problem, you will develop an operational semantics for PostFix that uses the RVM. Keep in mind that operational semantics are defined in terms of an abstract machine - the RVM has infinite memory and executes infinitely quickly. Don't worry if your operational semantics would be horribly inefficient or impractical if it were implemented on a concrete machine.

1. Justification
Without defining the semantics, argue that it must be possible to define an operational semantics for PostFix using the RVM.

2. Initial Configuration
The operational semantics requires a mapping from the program to an initial configuration. Describe how you will model a PostFix execution using the RVM. You shouldn't change C (the set of configurations), although you may use a different notation to describe a configuration if you want.

You may assume there are two functions:
           Encode: Postfix Command ==> Integer
           Decode: Integer ==> Postfix Command
such that Decode (Encode (command)) = command. As an exercise, convince yourself that these functions could be defined (you don't need to turn anything in for this). Recall that registers in the RVM can store infinitely large values.

Show explicitly how a PostFix program is mapped to an initial configuration. If you've thought about this for a while, and are stuck, you may consult the hint at http://www.cs.virginia.edu/~cs655/problem-sets/ps1-hint.html.

3. Final Configuration
Define the set of final configurations, and the output function from a final configuration to an answer.

4. Transition Rules
(a) Show the transition rule for < N . Q, S >.
(b) Show the transition rule for < add . Q, V1 . V2 . S >.
(c) Show the transition rule for < swap . Q, V1 . V2 . S >.
(d) (Challenge) Show the transition rule for <exec . Qrest, Qexec . S>.

Note: Problems marked Challenge are meant to be especially challenging. It isn't necessary to solve them to get a good grade on a problem set. You should attempt them, and write down your thoughts, but only spend an inordinate amount of time on them for your own enjoyment.

Hint: You may use Instruction[-1] ... Instruction[-infinity].

5. Termination
Turbak and Gifford's notes show how to prove that all PostFix programs terminate using the stack-based virtual machine. In class, we saw a proof that all BARK-forward programs terminate using the RVM.

(a) Construct a proof that all PostFix programs terminate using the operational semantics you defined in questions 2-4. For this problem, assume a simplified PostFix with three commands (corresponding to the transition rules you defined in question 4a-c): N, add and swap.

(b) (Grand Challenge!) Using your RVM operational semantics, show the termination property is true for PostFix with the exec command also.

Note: Problems marked Grand Challenge! are meant to be extremely difficult. The course staff doesn't necessarily know the answer to them, or even if they are possible to solve. A good solution to a Grand Challenge! problem (or a proof that no solution exists) should impress the staff and your classmates greatly.


CS 655 University of Virginia
CS 655: Programming Languages
cs655-staff@cs.virginia.edu
Last modified: Mon Feb 26 12:48:15 2001