Commit | Line | Data |
---|---|---|
28875fec SK |
1 | type oper = |
2 | | PlusOp | |
3 | | MinusOp | |
4 | | TimesOp | |
5 | | DivideOp | |
6 | | EqOp | |
7 | | NeqOp | |
8 | | LtOp | |
9 | | LeOp | |
10 | | GtOp | |
11 | | GeOp | |
12 | ||
13 | type exp = | |
28875fec SK |
14 | | NilExp |
15 | | IntExp of | |
16 | int | |
17 | | StringExp of | |
18 | { string : string | |
5597e56d | 19 | ; pos : Tiger_position.t |
28875fec SK |
20 | } |
21 | | CallExp of | |
5597e56d | 22 | { func : Tiger_symbol.t |
28875fec | 23 | ; args : exp list |
5597e56d | 24 | ; pos : Tiger_position.t |
28875fec SK |
25 | } |
26 | | OpExp of | |
27 | { left : exp | |
28 | ; oper : oper | |
29 | ; right : exp | |
5597e56d | 30 | ; pos : Tiger_position.t |
28875fec SK |
31 | } |
32 | | RecordExp of | |
5597e56d SK |
33 | { fields : (Tiger_symbol.t * exp * Tiger_position.t) list |
34 | ; typ : Tiger_symbol.t | |
35 | ; pos : Tiger_position.t | |
28875fec SK |
36 | } |
37 | | SeqExp of | |
5597e56d | 38 | (exp * Tiger_position.t) list |
28875fec SK |
39 | | AssignExp of |
40 | { var : var | |
41 | ; exp : exp | |
5597e56d | 42 | ; pos : Tiger_position.t |
28875fec SK |
43 | } |
44 | | IfExp of | |
45 | { test : exp | |
46 | ; then' : exp | |
47 | ; else' : exp option | |
5597e56d | 48 | ; pos : Tiger_position.t |
28875fec SK |
49 | } |
50 | | WhileExp of | |
51 | { test : exp | |
52 | ; body : exp | |
5597e56d | 53 | ; pos : Tiger_position.t |
28875fec SK |
54 | } |
55 | | ForExp of | |
5597e56d | 56 | { var : Tiger_symbol.t |
28875fec SK |
57 | ; escape : bool ref (* Whoa - why a mutable cell in AST? *) |
58 | ; lo : exp | |
59 | ; hi : exp | |
60 | ; body : exp | |
5597e56d | 61 | ; pos : Tiger_position.t |
28875fec SK |
62 | } |
63 | | BreakExp of | |
5597e56d | 64 | Tiger_position.t |
28875fec SK |
65 | | LetExp of |
66 | { decs : dec list | |
67 | ; body : exp | |
5597e56d | 68 | ; pos : Tiger_position.t |
28875fec SK |
69 | } |
70 | | ArrayExp of | |
5597e56d | 71 | { typ : Tiger_symbol.t |
28875fec SK |
72 | ; size : exp |
73 | ; init : exp | |
5597e56d | 74 | ; pos : Tiger_position.t |
28875fec | 75 | } |
5597e56d SK |
76 | | VarExp of |
77 | var | |
28875fec SK |
78 | and var = |
79 | | SimpleVar of | |
5597e56d SK |
80 | { symbol : Tiger_symbol.t |
81 | ; pos : Tiger_position.t | |
28875fec SK |
82 | } |
83 | | FieldVar of | |
84 | { var : var | |
5597e56d SK |
85 | ; symbol : Tiger_symbol.t |
86 | ; pos : Tiger_position.t | |
28875fec SK |
87 | } |
88 | | SubscriptVar of | |
89 | { var : var | |
90 | ; exp : exp | |
5597e56d | 91 | ; pos : Tiger_position.t |
28875fec SK |
92 | } |
93 | and dec = | |
94 | | FunDecs of (* "FunctionDec" in Appel's code *) | |
95 | fundec list | |
96 | | VarDec of | |
5597e56d | 97 | { name : Tiger_symbol.t |
28875fec | 98 | ; escape : bool ref (* Again, why mutable? *) |
5597e56d | 99 | ; typ : (Tiger_symbol.t * Tiger_position.t) option |
28875fec | 100 | ; init : exp |
5597e56d | 101 | ; pos : Tiger_position.t |
28875fec SK |
102 | } |
103 | | TypeDecs of (* "TypeDec" in Appel's code *) | |
104 | typedec list | |
105 | and ty = | |
106 | | NameTy of | |
5597e56d SK |
107 | { symbol : Tiger_symbol.t |
108 | ; pos : Tiger_position.t | |
28875fec SK |
109 | } |
110 | | RecordTy of | |
111 | field list | |
112 | | ArrayTy of | |
5597e56d SK |
113 | { symbol : Tiger_symbol.t |
114 | ; pos : Tiger_position.t | |
28875fec SK |
115 | } |
116 | and field = | |
117 | | Field of | |
5597e56d | 118 | { name : Tiger_symbol.t |
28875fec | 119 | ; escape : bool ref |
5597e56d SK |
120 | ; typ : Tiger_symbol.t |
121 | ; pos : Tiger_position.t | |
28875fec SK |
122 | } |
123 | and typedec = | |
124 | | TypeDec of (* An anonymous record in Appel's code *) | |
5597e56d | 125 | { name : Tiger_symbol.t |
28875fec | 126 | ; ty : ty |
5597e56d | 127 | ; pos : Tiger_position.t |
28875fec SK |
128 | } |
129 | and fundec = | |
130 | | FunDec of | |
5597e56d | 131 | { name : Tiger_symbol.t |
28875fec | 132 | ; params : field list |
5597e56d | 133 | ; result : (Tiger_symbol.t * Tiger_position.t) option |
28875fec | 134 | ; body : exp |
5597e56d | 135 | ; pos : Tiger_position.t |
28875fec SK |
136 | } |
137 | ||
138 | type t = exp | |
139 | ||
140 | val to_string : t -> string | |
c16dd441 SK |
141 | |
142 | val op_show : oper -> string |