-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbsGrammar.hs
94 lines (77 loc) · 1.95 KB
/
AbsGrammar.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
-- File generated by the BNF Converter (bnfc 2.9.4).
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- | The abstract syntax of language grammar.
module AbsGrammar where
import Prelude (Integer, String)
import qualified Prelude as C (Eq, Ord, Show, Read)
import qualified Data.String
data Program = Program [TopDef]
deriving (C.Eq, C.Ord, C.Show, C.Read)
data TopDef = FnDef Type Ident [Arg] Block
deriving (C.Eq, C.Ord, C.Show, C.Read)
data Arg = Arg Type Ident
deriving (C.Eq, C.Ord, C.Show, C.Read)
data Block = Block [Stmt]
deriving (C.Eq, C.Ord, C.Show, C.Read)
data Stmt
= Empty
| BStmt Block
| Decl Type [Item]
| Ass Ident Expr
| AddArr Ident Expr Expr
| Incr Ident
| Decr Ident
| Ret Expr
| VRet
| Cond Expr Stmt
| CondElse Expr Stmt Stmt
| While Expr Stmt
| For Ident Expr Expr Stmt
| Repeat Expr Stmt
| SExp Expr
| Break
| Continue
| Print Expr
deriving (C.Eq, C.Ord, C.Show, C.Read)
data Item
= NoInit Ident
| Init Ident Expr
| NoInitArr Ident Expr
| InitArr Ident Expr [Expr]
deriving (C.Eq, C.Ord, C.Show, C.Read)
data Type
= Int
| Str
| Bool
| Void
| ConstInt
| ConstStr
| ConstBool
| Array Type
| Fun Type [Type]
deriving (C.Eq, C.Ord, C.Show, C.Read)
data Expr
= Ekrotka [Expr]
| EArrayVar Ident Expr
| EVar Ident
| ELitInt Integer
| ELitTrue
| ELitFalse
| EApp Ident [Expr]
| EString String
| Neg Expr
| Not Expr
| EMul Expr MulOp Expr
| EAdd Expr AddOp Expr
| ERel Expr RelOp Expr
| EAnd Expr Expr
| EOr Expr Expr
deriving (C.Eq, C.Ord, C.Show, C.Read)
data AddOp = Plus | Minus
deriving (C.Eq, C.Ord, C.Show, C.Read)
data MulOp = Times | Div | Mod
deriving (C.Eq, C.Ord, C.Show, C.Read)
data RelOp = LTH | LE | GTH | GE | EQU | NE
deriving (C.Eq, C.Ord, C.Show, C.Read)
newtype Ident = Ident String
deriving (C.Eq, C.Ord, C.Show, C.Read, Data.String.IsString)