-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAST.hs
74 lines (61 loc) · 1.87 KB
/
AST.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
71
72
73
74
module AST where
import qualified Data.ByteString as B
import qualified Data.Map.Strict as M
import Data.Maybe
type VarName = String
data Type = Int
| Bool
| String
| Bits
| Void
| Double
| Fun [Type] Type
| ArrT Type (Maybe Int)
| Invalid -- Dummy type
deriving (Eq, Show)
cmtTypeTable = [("int", Int), ("bool", Bool), ("string", String),
("bits", Bits), ("void", Void), ("double", Double)]
data BinOp = Plus | Minus | Div | Prod | Eq | Mod
| Xor | And | Or | Band | Bor | BConcat
| LShift | RShift | LRot | RRot
| Le | Ge | Lt | Gt
deriving (Eq, Show)
data UnOp = Neg | Not | Bnot
deriving (Eq, Show)
data Expr = ConstInt Int
| ConstFloat Double
| ConstBool Bool
| BinOp BinOp Expr Expr
| UnOp UnOp Expr
| Call VarName [Expr]
| LV LValue
| ConstStr String
| BinLit [Int] Expr -- bytes and length in *bits*
| Arr [Expr]
| Slice Expr Expr Expr -- Array, From, To
deriving (Eq, Show)
data Stmt = Skip
| Assign LValue Expr
| If Expr Stmt Stmt
| Seq Stmt Stmt
| Return Expr
| Decl Decl
| For VarName Expr Expr Stmt
| Err String
deriving (Eq, Show)
data LValue = Var String
| Access LValue Expr
deriving (Eq, Show)
data Mods = Const | Extern | Static
deriving (Eq, Show)
data Decl = VarDecl String [Mods] (Maybe Type) (Maybe Expr)
| FunDecl { name :: String,
ret :: Type,
args :: [(String, Type)],
mods :: [Mods],
body :: Stmt }
deriving (Eq, Show)
type Prog = [Decl]
sseq Skip s = s
sseq s Skip = s
sseq s t = Seq s t