Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION.

Similar presentations


Presentation on theme: "School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION."— Presentation transcript:

1 School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION IN HASKELL PRACTICAL AND DURING THE WEEK: Do practical exercises to be given out..

2 School of Computing and Mathematics, University of Huddersfield HASKELL IMPLEMENTATION OF LAST WEEKS LANGUAGE n NB implementations always add extra “detail” that doesn’t occur in the abstract definition. Some syntax is necessarily different n I’ve cut a few corners to keep it simple – not all the error situations are specified

3 School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX data Exp = SN Int | SB Bool | SV Identifier | SC Identifier | Plus Exp Exp | Minus Exp Exp | GT Exp Exp data Cmd = Assigns Identifier Exp | Sequence Cmd Cmd | While Exp Cmd | Block Dec Cmd data Dec = Const Identifier Exp | Var Identifier Exp

4 School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX - EXAMPLE (Block (Var 'r' (SV 'y')) (Block (Var 'q' (SN 0)) (While (GT (SV 'r') (SV 'x')) (Sequence (Assigns 'r' (Minus (SV 'r') (SV 'x') )) (Assigns 'q' (Plus (SV 'q') (SN 1 ) )) ) Example “Concrete Syntax”.. {Var r = y; {Var q = 0; while r > x do {r = r-x; q = q+1} }

5 School of Computing and Mathematics, University of Huddersfield SEMANTIC DOMAINS -- values and locations data V = VB Bool | VN Int | V_error data D = LC Loc | EB Bool | EN Int | D_error -- the MAPS environments and stores are -- represented as a sequence of pairs data U = UCons Identifier D U | UNull | U_error data S = SCons Loc V S | SNull | S_error

6 School of Computing and Mathematics, University of Huddersfield AUXILIARY FUNCTIONS contents :: Loc -> S -> V contents l s = applyS s l update :: Loc -> V -> S -> S update l v s = overwrite s l v new :: S -> Loc new s = (maxloc 0 s)+1 maxloc :: Int -> S -> Int maxloc i SNull = i maxloc i (SCons l v s) | l > i = maxloc l s | otherwise = maxloc i s

7 School of Computing and Mathematics, University of Huddersfield meaning functions- Emeans -- exp is a var emeans (SV x) u S_error = V_error emeans (SV x) u s = contents l s where l = get_loc (applyU u x) NB extra selector function because applyU returns a Denotable value! get_loc :: D -> Loc get_loc (LC l) = l

8 School of Computing and Mathematics, University of Huddersfield meaning functions- Dmeans dmeans :: Dec -> U -> S -> (U,S) dmeans (Const id exp) u s = (UCons id e UNull, s) where e = get_exp (emeans exp u s) -- -- (NB get_exp :: V -> D) dmeans (Var id exp) u s = (UCons id (LC l) UNull, update l e s) where e = (emeans exp u s) l = new s

9 School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans - assignment cmeans (Assigns id exp) u s = update l v s where l = get_loc (applyU u id) v = emeans exp u s -- Sequence of two or more commands cmeans (Sequence c1 c2) u s = cmeans c2 u (cmeans c1 u s)

10 School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans -- meaning of a block command cmeans (Block dec c) u s = cmeans c u2 s1 where u1 = fst (dmeans dec u s) s1 = snd (dmeans dec u s) u2 = env_overwrite u u1

11 School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans cmeans (While exp c) u s | val (emeans exp u s) == False = s | otherwise = cmeans (While exp c) u (cmeans c u s)


Download ppt "School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION."

Similar presentations


Ads by Google