-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast_common.ml
70 lines (57 loc) · 1.61 KB
/
ast_common.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
type ident_desc = string (* only lowercase letters, can be "put", "new_line",
"character'val"... *)
type binop =
| Beq | Bneq
| Blt | Bleq | Bgt | Bgeq
| Bplus | Bminus | Btimes | Bdiv | Brem
| Band | Band_then | Bor | Bor_else
type const =
| Cint of int
| Cchar of char
| Cbool of bool
| Cnull
type mode = In | InOut
type 'ident typ_annot = (* Type annotated by the user *)
{
typ_ident: 'ident;
is_access: bool;
}
type 'ident annotated =
{
ident: 'ident;
ta : 'ident typ_annot;
}
let map_ta f ta =
{ ta with typ_ident = f ta.typ_ident }
let map_a f a =
{ ident = f a.ident; ta = map_ta f a.ta }
open Format
open Printer
let print_ident_desc fmt (id : ident_desc) =
fprintf fmt "%s" id
let print_binop fmt b =
fprintf fmt (match b with
| Beq -> "="
| Bneq -> "/="
| Blt -> "<"
| Bleq -> "<="
| Bgt -> ">"
| Bgeq -> ">="
| Bplus -> "+"
| Bminus -> "-"
| Btimes -> "*"
| Bdiv -> "/"
| Brem -> "rem"
| Band -> "and"
| Band_then -> "and then"
| Bor -> "or"
| Bor_else -> "or else"
)
let print_const fmt = function
| Cint n -> fprintf fmt "%d" n
| Cchar c -> fprintf fmt "%c" c
| Cbool b -> fprintf fmt "%b" b
| Cnull -> fprintf fmt "null"
let print_mode fmt = function
| In -> fprintf fmt "in"
| InOut -> fprintf fmt "in out"