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).

  1. Abstract Syntax:
    1. Syntactic domains:
      • P ε Program
      • C ε Command
      • E ε Expression
      • B ε BooleanExpression
      • I ε Identifier
      • N ε Numeral

    2. Grammar:
        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

  2. Semantic algebras:
    1. Truth Values
      Domain
      tr ε Tr = bool
      Operators
      true, false: Tr
      not: Tr → Tr

    2. Identifiers
      Domain
      i ε Id = Identifier

    3. Natural Numbers
      Domain
      n ε Nat = N
      Operators
      zero, one, ... : Nat
      plus: (Nat x Nat) → Nat
      dividedBy: (Nat x Nat) → Nat
      equals: (Nat x Nat) → Tr

    4. Store
      Domain
      s ε Store = Id → Nat
      Operators
      (1) newstore: Store = λi.zero (initially, a store maps all IDs to zero)
      (2) access: Id → (Store → Nat) = λi.λs.s i (the access operator lets you look up the value of an Id in a Store).
      (3) update: Id → Nat → Store → Store = λi.λn.λs.[ i |→ n ] s (This creates a function that is the same as s, except that when the input is i it returns n. The function can be written as: λj.if j == i then n else s j)

    5. Command Continuations
      Domain
      c ε Cc = Store → Store

    6. Expression Continuations
      Domain
      k ε Ec = Nat → Store → Store

    7. BooleanExpression Continuations
      Domain
      b ε Bc = Tr → Store → Store

  3. Valuation Functions