CS 3520 Homework 12   - Due December 6

Exercise 12.1, Continuations

The following are possible states of the interepreter with continuations. In each case, what will the final value of the program be?
  1. exp: 1
    env: {}
    cnt: [primother +, 2, {}, [done]]
  2. exp: x
    env: {x=12, {x=10, {}}}
    cnt: [primother +, x, {x=10, {}}, [done]]
  3. val: 10
    cnt: [app <x, proc(y)+(y, 5), {}>, [apparg 12, {}, [done]]]
  4. val: <x, proc(y)-(y, x), {x=6, {}}>
    cnt: [apparg 10, {x=6, {}}, [apparg 12, {x=6, {}}, [done]]]
Express your answer as a function answer-for-12.1 that takes no arguments and returns a list of 4 numbers.

Exercise 12.2, Garbage collection

Suppose a garbage-collected interepreter uses the following four kinds of records:(An "integer" is an immediate integer, not a tagged integer representing a value in the interpreted language.)

The interpreter has two registers, which always contain pointers, and a memory pool of size 30. The allocator/collector is a two-space copying collector, so each space is of size 15. Records are allocated consecutively in to-space, starting from the first memory location, 0.

The following is a snapshot of memory just before a collection where all memory has been allocated:

What are the values in the two registers and the new to-space after collection? Assume that unallocated memory in to-space contains 0.

Express your answer as a function answer-for-12.2 that takes no arguments and returns a list of 17 numbers (register 1, then register 2, then to-space slots).

Exercise 12.3, Formal semantics, expressions and values

Here's a grammar of expressions:

M=zero
 |(add1 M)
 |(sub1 M)

Here's a grammar for values, a subset of expressions:

V=zero
 |(add1 V)

Which of the following expressions are values?
  1. zero
  2. (add1 zero)
  3. (sub1 (add1 zero))
  4. (add1 (sub1 zero))
  5. (add1 (add1 (add1 zero)))
Express your answer as a function answer-for-12.3 that takes no arguments and returns a list of 5 booleans (#t for values, #f for non-values).

Exercise 12.4, Formal semantics, reduction

Here is a grammar of contexts, to go with the expressions and values of the previous exercise:

E=[]
 |(add1 E)
 |(sub1 E)

Here are the reduction rules:

(sub1 (add1 V))->V
E[M]->E[M'] where M -> M'

Which of the following expressions can be reduced to values?
  1. zero
  2. (add1 (sub1 zero))
  3. (sub1 (add1 zero))
  4. (sub1 (add1 zero))  -  same as #3
  5. (sub1 (sub1 (add1 (add1 zero))))
  6. (sub1 (add1 (sub1 (add1 zero))))
  7. (sub1 (add1 (sub1 (sub1 (add1 zero)))))
Express your answer as a function answer-for-12.4 that takes no arguments and returns a list of 7 booleans (#t for reducible to a value, #f for eventually stuck).


Last update: Tuesday, December 5th, 2000
mflatt@cs.utah.edu