-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.mli
76 lines (61 loc) · 1.8 KB
/
ast.mli
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
(* ast.mli *)
(* Abstract syntax of expressions. *)
(******************************************************************************)
(** Unary operators. *)
type unop =
| Neg (* unary signed negation *)
| Lognot (* unary logical negation *)
| Not (* unary bitwise negation *)
(** Binary operators. *)
type binop =
| Plus (* binary signed addition *)
| Times (* binary signed multiplication *)
| Minus (* binary signed subtraction *)
| Eq (* binary equality *)
| Neq (* binary inequality *)
| Lt (* binary signed less-than *)
| Lte (* binary signed less-than or equals *)
| Gt (* binary signed greater-than *)
| Gte (* binary signed greater-than or equals *)
| And (* binary bitwise and *)
| Or (* binary bitwise or *)
| Shl (* binary shift left *)
| Shr (* binary logical shift right *)
| Sar (* binary arithmetic shift right *)
(** Expressions. *)
type exp =
| Cint of int32
| Id of string
| Binop of binop * exp * exp
| Unop of unop * exp
type typ =
| TInt
type var_decl = {
v_ty : typ;
v_id : string;
v_init : exp;
}
type lhs =
| Var of string
(** Blocks and Statements. *)
type block = var_decl list * stmt list
and stmt =
| Assign of lhs * exp
| If of exp * stmt * stmt option
| While of exp * stmt
| For of (var_decl list) * exp option * stmt option * stmt
| Block of block
type prog = block * exp
val print_typ : typ -> unit
val string_of_typ : typ -> string
val ml_string_of_typ : typ -> string
val print_exp : exp -> unit
val string_of_exp : exp -> string
val ml_string_of_exp : exp -> string
val print_stmt : stmt -> unit
val string_of_stmt : stmt -> string
val ml_string_of_stmt : stmt -> string
val print_prog : prog -> unit
val string_of_prog : prog -> string
val ml_string_of_prog : prog -> string
val interpret_exp : exp -> (string * int32) list -> int32