School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL...

12
School of Comput ing and Mathemat ics, University CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises given out DURING THE WEEK: Go through ARJ’s supporting WEB notes (from main web page).

Transcript of School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL...

Page 1: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

CHA2545: WEEK 4

LECTURE:

DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE

TUTORIAL:

Do exercises given out

DURING THE WEEK:

Go through ARJ’s supporting WEB notes (from main web page).

Page 2: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

The Four Parts of a Semantic Definition:

Syntactic domains Abstract Syntax Semantic Domains Meaning Functions

Example syntax domains (see handout)

Nml, Ide, Exp, Cmd

Page 3: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

DENOTATIONS

The semantics of the various syntactic structures of a language is defined via meaning functions which take the syntactic structure as a parameter and returns its denotation.

A “denotation” is a mathematical representation of the meaning of a construct - its an object belonging to a SEMANTIC DOMAIN.

Page 4: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

SEMANTIC DOMAINS - Examples

Simple Semantic Domains -

T - truth values

N - natural numbers

Z - integers

Complex Domains

are made up by combining Simple Domains with operators such as +, x, ->

Page 5: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

COMPLEX DOMAINS - Examples Disjoint Union Domain of all integers and truth

values

Z + T Cross Product Domain of all pairs of integers

Z x Z Function Domain consisting of all functions

from integers to truth values

Z -> Z

and pairs of integers to integers

(Z x Z) -> Z

Page 6: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

COMPLEX DOMAINS - Another Example

All “expressible” values in a simple programming language with truth values and natural numbers:

E = N + T + {error}

Page 7: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

The STORE

The simplest way to represent the STATE of program execution is by a STORE - representing the values stored at any point in the execution of a program.

The store is represented by a function domain

S = [ Ide -> E ] + {error}

We usually let ‘s’ be a typical store or state.

Page 8: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

Commands

Commands change the program state

The domain of commands is therefore the functions between states, i.e.

S -> S

Page 9: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

Semantic Function: Emeans

Emeans takes a syntactically well formed expression, and gives it a denotation in terms of a

function between stores and expressible values

so

Emeans : Exp -> S -> E

The definition of Emeans depends on the syntactic subclass to which it is applied.

Page 10: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

Semantic Function: Cmeans

Cmeans takes a syntactically well formed command, and gives it a denotation in terms of a

function between stores and stores

so

Cmeans : Cmd -> S -> S

The definition of Cmeans depends on the syntactic subclass to which it is applied

Page 11: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

The Problem with Recursive Functions - what do they mean?

Cmeans[[while B do C]] =

s.(Emeans[[B]]s ->

Cmeans[[while B do C]](Cmeans[[C]]s), s)

OR:

Cmeans[[while B do C]] = f where

f = s.(Emeans[[B]]s -> f(Cmeans[[C]]s), s)

Page 12: School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.

School of Computing and Mathematics, University of Huddersfield

Recursive Functions - The Fixpoint Equation

Given:

f = s.(Emeans[[B]]s -> f(Cmeans[[C]]s), s)

Then:

H = f.s.(Emeans[[B]]s -> f(Cmeans[[C]]s), s)

Hf = (f.s.(Emeans[[B]]s -> f(Cmeans[[C]]s), s)) f

= s.(Emeans[[B]]s -> f(Cmeans[[C]]s), s)

= f

SO WE HAVE Hf = f - the fixpoint equation!!