[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]

The following is an example, intended to provide an introduction to denotational semantics. The details of the example are (or will be) covered in class.

P in Prog L in SL S in Stat E in Exp V in Val I in Ide

// ProgramsProg => L// Lists of statementsSL => S | S ; L// StatementsStat => I = E | if E then L fi | if E then L0 else L1 fi | while E do L od | read(I) | write(E)// ExpressionsExp => E_{1}+ E_{2}| E_{1}* E_{2}| E_{1}- E_{2}| E_{1}/ E_{2}| (E) | V | I

n in NNatural Numbersenv in U = Id -> NEnvironmentsinp in I = N*Input (a sequence of numbers)out in O = N*Output (a sequence of numbers)cont in C = U -> I -> OContinuations

meaningProg : Prog -> I -> O meaningSL : SL -> C-> U -> I -> -> O meaningStat : Stat -> C -> U -> I -> O meaningExp : Exp -> U -> N meaningVal : Val -> N

`meaningProg`

meaningProg[[SL]] = meaningSL[[SL]] cleanup basicEnv

`meaningSL`

meaningSL[[S;L]] = \cont . \env . \inp . meaningS[[S]] (meaningSL[[L]]] cont) env inp meaningSL[[S]] = meaningS[[S]]

`meaningStat`

meaningStat[[read(I)]] = \cont . \env . \inp . cont (setenv env I (car inp)) (cdr inp) meaningStat[[write(E)]] = \cont . \env . \inp . cons (meaningExp E env) (cont env inp) meaningStat[[I = E]] = \cont . \env . \inp . cont (setenv env I (meaningExp E env)) inp meaningStat [[if E then L_{1}else L_{2}fi]] = \cont . \env . \inp . (meaningExp E env) = 0 -> meaningSL L_{2}cont env inp , meaningSL L_{1}cont env inp meaningStat [[if E then L fi]] = \cont . \env . \inp . (meaningExp E env) = 0 -> cont env inp ; meaningSL L cont env inp meaningStat[[while E do L od]] = F(E,L) s.t. F(E,L) : C -> U -> I -> O F(E,L) cont env inp = ((meaningExp E env) == 0) -> cont env inp, meaningSL L (\e . \i . F(E,L) cont e i ) env inp

`meaningExp`

meaningExp [[E_{1}+ E_{2}]] = \env . (meaningExp E_{1}env) + (meaningExp E_{2}env) meaningExp [[E_{1}- E_{2}]] = \env . (meaningExp E_{1}env) - (meaningExp E_{2}env) meaningExp [[E_{1}* E_{2}]] = \env . (meaningExp E_{1}env) * (meaningExp E_{2}env) meaningExp [[E_{1}/ E_{2}]] = \env . (meaningExp E_{1}env) / (meaningExp E_{2}env) meaningExp [[I]] = \env . (env I) meaningExp [[V]] = \env . meaningVal V meaningExp [[(E)]] = meaningExp E

`meaningVal`

*This function has the ``obvious'' definition, which is
difficult to express. Basically, it maps every string of digits
to the corresponding number.*

// Build a basic environment that assigns 0 to every variable.basicEnv : U basicEnv = \x . 0// A continuation used to ``clean up'' at the end of the program.cleanup : C cleanup = \env . \inp . nil// Set the value associated with an identifier in an environment.setenv : U -> Id -> N -> U setenv env id num = \x . (x == id) -> num , (env id)

- Created Friday, March 12, 1999. Based, primarily, on outline 12 and notes on assignment 3 from CS302 99S.
- Made a few minor changes on Monday, March 15, 1999.

[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]

**Disclaimer** Often, these pages were created ``on the fly'' with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS302/99S/Handouts/simple-semantics.html

Source text last modified Mon Mar 15 08:13:28 1999.

This page generated on Mon Mar 15 08:43:16 1999 by SiteWeaver. Validate this page's HTML.

Contact our webmaster at rebelsky@math.grin.edu