forked from byorgey/it-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItLang.hs
70 lines (48 loc) · 1.44 KB
/
ItLang.hs
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
{-# LANGUAGE GADTs #-}
module ItLang where
import qualified Data.Map as M
import Data.Maybe
type Var = String
data Nat where
Z :: Nat
S :: Nat -> Nat
deriving (Eq, Ord)
type Prog = [Stmt]
data Stmt where
Assign :: Var -> Exp -> Stmt
Block :: Prog -> Stmt
If :: BExp -> Stmt -> Stmt -> Stmt
Repeat :: Exp -> Stmt -> Stmt
data Exp where
Lit :: Nat -> Exp
V :: Var -> Exp
Plus :: Exp -> Exp -> Exp
Minus :: Exp -> Exp -> Exp
Times :: Exp -> Exp -> Exp
data BExp where
BLit :: Bool -> BExp
Eq :: Exp -> Exp -> BExp
Lt :: Exp -> Exp -> BExp
Not :: BExp -> BExp
Or :: BExp -> BExp -> BExp
And :: BExp -> BExp -> BExp
type Mem = M.Map Var Nat
------------------------------------------------------------
evalExp :: Exp -> Mem -> Nat
evalExp = undefined
------------------------------------------------------------
evalBExp :: BExp -> Mem -> Bool
evalBExp = undefined
------------------------------------------------------------
execStmt :: Stmt -> Mem -> Mem
execStmt = undefined
------------------------------------------------------------
execProg :: Prog -> Mem -> Mem
execProg [] m = m
execProg (x:xs) m = execProg xs (execStmt x m)
------------------------------------------------------------
execRepeat :: Nat -> Stmt -> Mem -> Mem
execRepeat = undefined
------------------------------------------------------------
-- M.insert :: Var -> Nat -> Mem -> Mem
memLookup v m = fromMaybe 0 (M.lookup v m)