Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 – SEMANTICS EXAMPLE LECTURE: SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL:

Similar presentations


Presentation on theme: "School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 – SEMANTICS EXAMPLE LECTURE: SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL:"— Presentation transcript:

1 School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 – SEMANTICS EXAMPLE LECTURE: SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL: - Last weeks exercise 5 - Haskell/Gofer revision..follow WEB NOTES/EXERCISES NB supporting notes for all these topics in web page

2 School of Computing and Engineering, University of Huddersfield DENOTATIONAL SEMANTICS OF BINARY NUMERALS In a denotational defn, we MAP abstract syntax classes to meanings (explicit objects) in a well known language! e.g. binary, octal, roman numeral => base 10 natural numbers

3 School of Computing and Engineering, University of Huddersfield BINARY NUMERALS: ABSTRACT SYNTAX 1 :  BinDidgit 0 :  BinDidgit D: BinDigit  BinNum N: BinNum BinDigit  BinNum NB: alternative notation: BinDigit => 1 | 0 BinNum => BinDigit | BinNum; BinDigit

4 School of Computing and Engineering, University of Huddersfield SEMANTICS meaning function M: -- maps BinNum to Decimals M[D 1] =1 --- 1 M[D 0] = 0 --- 2 M[ N n 0) ] = M[n] x 2 --- 3 M[ N n 1) ] = M[n] x 2 + 1 --- 4

5 School of Computing and Engineering, University of Huddersfield Binary Numerals: Example Meaning of 101 = M[N (N (D 1) 0) 1)] = M[N (D 1 ) 0 ] x 2 +1 using Rule 4 = (M[D 1] x 2) x 2 + 1 using Rule 3 = (1 x 2 ) x 2 + 1 using Rule 1 = 5

6 School of Computing and Engineering, University of Huddersfield BUT WHAT OF SEMANTICS OF NATURAL NUMBERS? We can give semantics via an algebraic specification (see later in the term) where we gave the essential meaning of “objects” in terms of a set of axioms which relate the syntactic expression -- the axioms say what expressions are equal.

7 School of Computing and Engineering, University of Huddersfield Giving semantics via algebra: Numbers zero :  Num successor : Num  Num add : Num Num  Num for all x,y in Num add(successor(x),y) = successor(add(x,y)) -- (1) add(zero,y) = y -- (2) add(x,y) = add(y,x) etc PROVE 1 + 1 =2 !!!!!

8 School of Computing and Engineering, University of Huddersfield Haskell The DENOTATIONS of Syntax Classes of Program Languages will be FUNCTIONS IN LAMBDA CALCULUS These can be written in Haskell (~= Gofer) Haskell is: The “standard” pure, lazy functional language Practical: Haskell revision

9 School of Computing and Engineering, University of Huddersfield Conclusion For each construct we can then give a (composite) semantic definition. The semantics of the language is then defined in terms of the semantics of each individual construct.


Download ppt "School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 – SEMANTICS EXAMPLE LECTURE: SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL:"

Similar presentations


Ads by Google