Here is the final continuation semantics for our simple procedural language including the "diverge" command, and division (with division by zero defined to be an error).
P | → | C. |
C | → | C1 ; C2 |
| | if B then C | |
| | if B then C1 else C2 | |
| | I = E | |
| | diverge | |
E | → | E1 + E2 |
| | E1 / E2 | |
| | I | |
| | N | |
B | → | E1 == E2 |
| | ! B | |
I | → | IDENT |
N | → | NUM |
P [[C.]] = λn. let s1 = (update [[A]] n newstore) in let s2 = C [[C]] (λs.s) s1 in (access [[Z]] s2)
C [[diverge]] = λc.λs. ⊥
C [[I=E]] = λc.λs1.E [[E]] (λn.λs2.c(update [[I]] n s2)) s1
C [[C1;C2]] = λc.λs.C [[C1]] (C [[C2]] c) s
C [[if B then C]] = λc.λs.B [[B]] (λtr.λs1.if tr then C [[C]] c s1 else c s1) s
C [[if B then C1 else C2]] = λc.λs.B [[B]] (λtr.λs1.if tr then C [[C1]] c s1 else C [[C2]] c s1) s
E [[N]] = λk. λs. k [[N]] s
E [[I]] = λk. λs. k (access[[I]] s) s
E [[E1+E2]] = λk.λs1.E [[E1]] (λn1. λs2. E [[E2]] (λn2. λs3. k (n1 plus n2) s3) s2) s1
E [[E1/E2]] = λk.λs1.E [[E2]] (λdenom. λs2. if (denom equals zero) then ⊥ else E [[E2]] (λnum. λs3. k (num dividedBy denom ) s3) s2) s1
B [[E1==E2]] = λb.λs. E [[E1]] (λv1.λs1. E [[E2]] (λv2.λs2. b(v1 equals v2) s2) s1) s
B [[!B]] : λb.λs. B [[B]] (λtr.λs1. b(not tr) s1) s