1
CS 611 Advanced Programming Languages
Andrew Myers Cornell University Lecture 10 Denotational semantics of IMP
15 Sep 00
CS 611 Fall '00 -- Andrew Myers, Cornell University 2
Operational vs. denotational
- Operational semantics
– meaning of program defined by syntactic transitions – structural operational semantics: how to write a recursive-descent interpreter – meaning of language terms defined by other language terms (λ x x) = (λ x x)
- Denotational semantics
– defines meaning of program in terms of underlying semantic domain (intrinsic meaning) – semantic function maps expressions to meanings – how to write a compiler
CS 611 Fall '00 -- Andrew Myers, Cornell University 3
Semantic Function
- Denotational semantics operates on
expressions to produce objects that are the meaning of the expression (usually mathematical function) C (λ x x) = λ x ∈ D. x
λ x x { (a, a) | a ∈ D}
CS 611 Fall '00 -- Andrew Myers, Cornell University 4
Parsing λ λ λ λ’s
- Notation for describing a mathematical
function of several variables: λxyz . e = λxλyλz . e
- Lambda expression extends as far to the right
as possible (like ∀, ∃) λxλyλz . x λw. w = λx(λy(λz . (x (λw. w)))) not ((λx(λy(λz . x))) (λw. w))
- Application left-associates:
xyz = (xy)z = x(y,z) f = λxyz . e fabc = f (a,b,c)
CS 611 Fall '00 -- Andrew Myers, Cornell University 5
Typed functions
- For mathematical functions, we will usually
write the types of the arguments PLUS = λx∈Z . λy∈Z. x+y = λx,y∈Z . x+y PLUS ∈ Z → (Z → Z)
- Type (T1 → T2) is domain of functions that
maps elements from domain T1 to domain T2
- Application associates to the left function
constructor (→) associates to right Z → (Z → Z) = Z → Z → Z
CS 611 Fall '00 -- Andrew Myers, Cornell University 6
Back to IMP
- Recall IMP has three kinds of expressions: