22 1 Midterm Sol
22 1 Midterm Sol
1) (5pts)
a) (1pt) syntax
b) (1pt) semantics
c) (1pt) concrete syntax
d) (1pt) abstract syntax
e) (1pt) parser
2) (5pts)
a) (3pts) 3->1, 4->2, 7->6, 9->5, 10->8
b) (2pts) 1->5, 1->6, 5->8 (allowed to include also 1->8)
-1pt per missing ->. if there’s no missing one, -1pt per wrong ->
3) (5pts) { x => y }
4) (10pts)
a) (2pts) bindings(b) + x
b) (3pts) bindings(b) ++ bindings(e) + f + x
c) (2pts) frees(b) - x
d) (3pts) (frees(b) - f - x) ++ (frees(e) - f)
No partial credit for each subquestion
5) (10pts) App(
App(
Fun("x", Fun("y", Fun("z",
App(App(Id("z"), Id("x")), Id("y"))
))),
desugar(f)
),
desugar(s)
)
Lazy pair: -3pts
No desugar: -3pts
Minor mistake: -1pt
1
6) (5pts) max(0, (number of correct answers) − 2 × (number of wrong answers)) pts
a) error
b) 120
c) 120
d) 120
e) 120
7) (10pts)
a) (6pts) { x => box.get(x) } (2pts for box.get)
b) (3pts) f or b(f)
c) (1pt) f or b(f) or box.get or openbox(box) or b(box.get) or b(openbox(box)) or · · ·
8) (5pts) { x => x }({ x => x }(1)), [], []
{ x => x }, [], []
{ x => x }(1), [], []
{ x => x }, [], []
1, [], []
x, [x -> 1], [1 -> 1]
x, [x -> 2], [1 -> 1, 2 -> 1]
-1pt per wrong line
9) (10pts)
a) (2pts) (PtrV(env(x)), sto)
b) (4pts) val (pv, ps) = interp(p, env, sto)
(ps(getAddr(pv)), ps)
10) (5pts) GWWW, BWGW, BWBG, BWBB or GWWW, GWGW, BWGW, BWGG, BWBG, BWBB
11) (15pts)
a) (9pts) heap(free) = heap(addr)
heap(free + 1) = heap(addr + 1)
heap(addr) = 99
heap(addr + 1) = free
free += 2
free - 2
b) (3pts) heap(addr + 1)
c) (3pts) heap(scan + 1) = copy(heap(scan + 1))
2
12) (5pts) { x => (x + x) }((1 + 2)), []
{ x => (x + x) }, [] (1pt)
(x + x), [x -> ((1 + 2), [])] (2pts)
x, [x -> ((1 + 2), [])] (1pt)
(1 + 2), [] (1pt)
1, []
2, []
x, [x -> ((1 + 2), [])]
(1 + 2), []
1, []
2, []
13) (10pts) σ`e⇒v σ ` e ⇒ v0 v0 ⇓ v
n⇓n hλx.e, σi ⇓ hλx.e, σi
a) (5pts) delay(e, σ) ⇓ v lazy(e, σ) ⇓ v
1pt 2pts 2pts
σ ` e ⇒ v0 v0 ⇓ v
σ ` delay e ⇒ delay(e, σ) σ ` lazy e ⇒ lazy(e, σ)
b) (5pts) σ ` force e ⇒ v
1pt 1pt 3pts