-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyntax.hs
More file actions
82 lines (70 loc) · 2.77 KB
/
Syntax.hs
File metadata and controls
82 lines (70 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{-# LANGUAGE GADTs #-}
module Syntax where
import Data.Maybe
import Types
-- funcion continua a la cual aplicar el t. del punto fijo
-- ∞
-- fix f = ⊔ fⁱ ⊥
-- i=0
fix :: (a -> a) -> a
fix f = f (fix f)
-- funciones auxiliares: aplicar funciones básicas a los valores Maybe
computeMaybe1 :: Maybe a -> (a -> b) -> Maybe b
computeMaybe1 Nothing f = Nothing
computeMaybe1 (Just x) f = Just (f x)
computeMaybe2 :: Maybe a -> Maybe a -> (a -> a -> b) -> Maybe b
computeMaybe2 Nothing _ f = Nothing
computeMaybe2 _ Nothing f = Nothing
computeMaybe2 (Just x) (Just y) f = Just (f x y)
-- Propagacion de error
(>>==) :: (Maybe a, Σ) -> (a -> Σ -> Ω) -> Ω
(>>==) (Nothing, σ) _ = Abort σ
(>>==) (Just n, σ) f = f n σ
-- Funciones de transferencia de control
(*.) :: (Σ -> Ω) -> Ω -> Ω
(*.) f (Normal σ) = f σ
(*.) _ (Abort σ) = Abort σ
(*.) f (Out (n,ω)) = Out (n, f *. ω)
(*.) f (In g) = In ((f *.) . g)
(†.) :: (Σ -> Σ) -> Ω -> Ω
(†.) f (Normal σ) = Normal $ f σ
(†.) f (Abort σ) = Abort $ f σ
(†.) f (Out (n,ω)) = Out (n, f †. ω)
(†.) f (In g) = In ((f †.) . g)
(+.) :: (Σ -> Ω) -> Ω -> Ω
(+.) _ (Normal σ) = Normal σ
(+.) f (Abort σ) = f σ
(+.) f (Out (n,ω)) = Out (n, f +. ω)
(+.) f (In g) = In ((f +.) . g)
-- Funcion de reemplazo de estado
update :: Σ -> Var -> Int -> Σ
update σ v n v' = if v == v' then n else σ v'
{- Sintaxis -}
data Expr a where
I :: Int -> Expr MInt
V :: Var -> Expr MInt
Op :: Expr MInt -> Expr MInt
(:+) :: Expr MInt -> Expr MInt -> Expr MInt
(:-) :: Expr MInt -> Expr MInt -> Expr MInt
(:*) :: Expr MInt -> Expr MInt -> Expr MInt
(:/) :: Expr MInt -> Expr MInt -> Expr MInt
(:%) :: Expr MInt -> Expr MInt -> Expr MInt
B :: Bool -> Expr MBool
Not :: Expr MBool -> Expr MBool
(:&&) :: Expr MBool -> Expr MBool -> Expr MBool
(:||) :: Expr MBool -> Expr MBool -> Expr MBool
(:==) :: Expr MInt -> Expr MInt -> Expr MBool
(:<) :: Expr MInt -> Expr MInt -> Expr MBool
(:>) :: Expr MInt -> Expr MInt -> Expr MBool
(:<=) :: Expr MInt -> Expr MInt -> Expr MBool
(:>=) :: Expr MInt -> Expr MInt -> Expr MBool
Skip :: Expr Ω
(:=) :: Var -> Expr MInt -> Expr Ω -- Asignacion
(:.) :: Expr Ω -> Expr Ω -> Expr Ω -- Concatenacion
IfThenElse :: Expr MBool -> Expr Ω -> Expr Ω -> Expr Ω
NewvarIn :: Var -> Expr MInt -> Expr Ω -> Expr Ω
WhileDo :: Expr MBool -> Expr Ω -> Expr Ω
Fail :: Expr Ω
(:.>) :: Expr Ω -> Expr Ω -> Expr Ω -- catch (arg 1) with (arg 2)
Print :: Expr MInt -> Expr Ω
Input :: Var -> Expr Ω