1 / 11

CAS810: WEEK 7

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. HASKELL IMPLEMENTATION OF LAST WEEKS LANGUAGE.

paley
Download Presentation

CAS810: WEEK 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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. HASKELL IMPLEMENTATION OF LAST WEEKS LANGUAGE • NBimplementations 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 – not all the error situations are specified

  3. 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. 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. 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. 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. 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. 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. 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. 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. 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)

More Related