Denotational Semantics



Example: language of simple expressions

Introduces environments

Syntactic Categories

  I in Ident  (identifiers)
  E in Exp    (expressions)
Syntax BNF
   E  ::=  0 | 1 | I | (E1 + E2) | (E1 - E2) 
        |  let I = E1 in E2 end
Value Domains
          Int = { ..., -2, -1, 0, 1, 2, ... }   (integers)
   rho in Env = Ident --> Int                   (environment, values for variables)
Semantic Functions
   EE : Exp --> Env --> Int
Semantic Equations
   EE [0] rho  =  0
   EE [1] rho  =  1
   EE [I] rho  =  rho(I)
   EE [E1 + E2] rho  =  plus ( EE [E1] rho, EE [E2] rho )
   EE [E1 - E2] rho  =  minus ( EE [E1] rho, EE [E2] rho )

     note here the "+" and "-" on the left is SYNTAX. 
     The "plus" and "minus" on the right are operations defined on 
     corresponding value domains (here, Int, since EE generates Int)
     For this reason, you can think of the Value Domains as algebras...
     i.e., sets of values and operations on them, i.e., ADTs

   EE [[ let I = E1 in E2 end ]] rho  =  EE [[ E2 ]] (rho[I |-> EE [[E1]] rho ])