Download presentation

Presentation is loading. Please wait.

Published byPerla Townsell Modified over 3 years ago

1
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 5 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE : INTERPRETATION IN HASKELL FORMATIVE ASSESSMENT: Last week’s exercises, Cmeans[[if B then S1 else S2]] PRACTICAL AND DURING THE WEEK: Do practical exercises to be given out..

2
School of Computing and Mathematics, University of Huddersfield GOFER/HASKELL IMPLEMENTATION OF LAST WEEKS LANGUAGE An implementation should deepen your understanding of the semantic definition BUT - implementations always add extra “detail” that doesn’t occur in the abstract definition - some syntax is necessarily different - I’ve cut a few corners to keep it simple - some “implicit” things have to be explicitly defined e.g. The overwrite and apply functions for maps

3
School of Computing and Mathematics, University of Huddersfield GOFER/HASKELL IMPLEMENTATION PROGRAM TEXT ‘SYNTAX TREE’ PREFIX FORM (Plus (SI 'x') (SN 42))x + 42 Cons 'y' (VN 0) (Cons 'x' (VN (-3)) Null) STORE cmeans NEW STORE

4
School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX - is in PREFIX form - is like normal syntax onto which a PARSER has been applied, producing an abstract syntax tree e.g. PARSER(x + 42) = (Plus (SI 'x') (SN 42)) This latter syntax is what the ‘implementation’ (of the denotational defn) is applied to...

5
School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX -- abstract syntax -- --------------- data Exp = SN Int | SB Bool | SI Identifier | Plus Exp Exp data Cmd = Assigns Identifier Exp | Sequence Cmd Cmd | While Exp Cmd

6
School of Computing and Mathematics, University of Huddersfield SEMANTIC DOMAINS -- semantic domains -- ---------------- -- (1) expressible values data E = VB Bool | VN Int | E_error -- (2) stores data S = Cons Identifier E S | Null | S_error

7
School of Computing and Mathematics, University of Huddersfield STORE - FUNCTIONS apply :: S -> Identifier -> E apply Null j = E_error apply S_error j = E_error apply (Cons i e s) j | i == j = e | otherwise = apply s j

8
School of Computing and Mathematics, University of Huddersfield STORE - FUNCTIONS overwrite :: S -> Identifier -> E -> S overwrite s j E_error = S_error overwrite Null j e2 = (Cons j e2 Null) overwrite S_error j e2 = S_error overwrite (Cons i e1 s) j e2 | i == j = (Cons i e2 s) | otherwise = (Cons i e1 (overwrite s j e2))

9
School of Computing and Mathematics, University of Huddersfield meaning functions- Emeans emeans :: Exp -> S -> E emeans (SB True) s = (VB True) emeans (SN x) s = VN x emeans (SI x) S_error = E_error emeans (SI x) s = apply s x emeans (Plus e1 e2) S_error = E_error emeans (Plus e1 e2) s = add (emeans e1 s) (emeans e2 s)

10
School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans cmeans :: Cmd -> S -> S cmeans c S_error = S_error cmeans (Assigns id exp) s = overwrite s id (emeans exp s) cmeans (Sequence c1 c2) s = cmeans c2 (cmeans c1 s)

11
School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans cmeans :: Cmd -> S -> S cmeans (While exp c) s | val (emeans exp s) == 0 = s | otherwise = cmeans (While exp c) (cmeans c s) val :: E -> Int val (VN x) = x

12
School of Computing and Mathematics, University of Huddersfield TESTS astore = Cons 'y' (VN 0) (Cons 'x' (VN (-3)) Null) test1 = cmeans (Assigns 'x' (SN 42)) astore test2 = cmeans (Sequence (Assigns 'x' (SN 42)) (Assigns 'y' (SI 'x')) ) astore test3 = cmeans (While (SI 'x') (Sequence (Assigns 'x' (Plus (SI 'x') (SN 1)) ) (Assigns 'y' (Plus (SI 'y') (SN 1)) ) )) astore test4 = cmeans (Sequence (Assigns 'x' (SN 42)) (Assigns 'y' (SI 'z')) ) astore

Similar presentations

OK

1 6.001 SICP Variations on a Scheme Scheme Evaluator – A Grand Tour Techniques for language design: Interpretation: eval/apply Semantics vs. syntax Syntactic.

1 6.001 SICP Variations on a Scheme Scheme Evaluator – A Grand Tour Techniques for language design: Interpretation: eval/apply Semantics vs. syntax Syntactic.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on hr practices in banking sector Ppt on law of conservation of mass Ppt on electricity generation by walking Ppt on any state of india Ppt on 2nd world war deaths Ppt on acute and chronic renal failure Ppt on product advertising definition Ppt on weapons of mass destruction found Ppt on google file system Ppt on uses of plants for grade 1