-
Notifications
You must be signed in to change notification settings - Fork 0
/
snick_ast.ml
102 lines (85 loc) · 2.11 KB
/
snick_ast.ml
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
94
95
96
97
98
99
100
101
102
(*
** File: snick_ast.ml
** Description: Specification of the abstract syntax tree for Snick.
** Last Modified: Sun. 9th April 2017
**
** Group name: Mainframe
**
** Member names | usernames
** Xianzhuo REN | xianzhuor
** Haoyu LIN | haoyul3
** Zequn MA | zequnm
*)
(* identifier *)
type ident = string
(* primitive types *)
type snicktype =
| Bool
| Int
| Float
(* array dimensions *)
type interval = (int * int)
(* variable representations *)
type variable = Variable of (ident * interval list option)
(* single declation *)
type decl = (snicktype * variable)
(* operators *)
type optr =
| Op_or
| Op_and
| Op_not
| Op_eq | Op_ne | Op_lt | Op_gt | Op_le | Op_ge
| Op_add | Op_sub
| Op_mul | Op_div
| Op_minus
(* expression *)
type expr =
(* variable element expression*)
| Eelem of elem
(* constant expression *)
| Ebool of bool
| Eint of int
| Efloat of float
(* expression inside a pair of parentheses *)
| Eparen of expr
(* operation expression *)
| Ebinop of (expr * optr * expr)
| Eunop of (optr * expr)
(* element to read, write or assign *)
and elem = Elem of (ident * expr list option)
(* Expression that can be written (either an expression or string). *)
type write_expr =
| Expr of expr
| String of string
(* statement *)
type stmt =
(* atomic statement *)
| Assign of (elem * expr)
| Read of elem
| Write of write_expr
| Call of (ident * expr list)
(* composite statement *)
| If_then of (expr * stmt list)
| If_then_else of (expr * stmt list * stmt list)
| While of (expr * stmt list)
(* procedure body *)
type proc_body = {
decls : decl list ;
stmts : stmt list
}
(* parameter indicator *)
type param_indc =
| Val
| Ref
(* procedure parameter *)
type param = (param_indc * snicktype * ident)
(* procedure header *)
type proc_header = (ident * param list)
(* procedure *)
type proc = (proc_header * proc_body)
(* list of procedures *)
type procs = proc list
(* program is a list of procedures *)
type program = procs
(* root node of the ast *)
type t = program