Homework 3 - Denotational Semantics
Due: Sep 27 2PM in class or by email to instructor
For all problems, if you need to change the semantic domain with new
types or operations, you can either use operations well known to a high
school algebra student, or define the operations in precise English (or
a mathematical formalism such as lambda calculus, if you know it).
Problem 1 (30%)
Determine the denotational semantics of the following program. You may
skip steps (and clearly indicate that you are doing so) only in cases
where you have already done a similar statement.
x
:= 12;
y := 13-x;
if y-2 then
y := y+4
else
y := y+5
fi;
Problem 2 (35%)
You wish to extend Louden's language to add a repeatmod statement with the
abstract syntax, 'repeatmod' E L 'domtaeper'. Informally, this
statement executes L 0, 1, or 2 times depending on whether E is 0, 1,
or 2 (mod 3).
Note that the given informal semantics has an ambiguity that is
resolved in your formal semantics. Make sure to also describe
informally any corresponding changes to the informal semantics. In this
homework, you are being explicitly told about ambiguities; in the
future, you should always identify ambiguities by yourself.
Problem 3 (35%)
Now we wish to add an output statement with the abstract syntax,
'output' E. Modify the denotational semantics to support this.
Hint: Modify the environment as in the previous homework on operational
semantics. This time, you will need a list of output values (i.e., a
stream).
Homework
Corrections,
Clarifications, and Hints
- In all formal semantics problems this semester, you are not
allowed to change the set of legal identifiers. In other words, you
can't take the easy way out and reduce the problem of determining
formal semantics to one of writing a simple imperative program.
For example, if you were trying to write the semantics of a
statement, 'inc' V, which increments V, you are not allowed to do it
by saying it reduces to the semantics of "x := 1; V := V+x". Doing
that would mean you are no longer allowing a program to use the
variable x, which is not allowed.