-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.ml
More file actions
executable file
·70 lines (61 loc) · 1.87 KB
/
Copy pathsyntax.ml
File metadata and controls
executable file
·70 lines (61 loc) · 1.87 KB
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
open Format
type inst = string
type oper =
| Plus
| Minus
| Times
| And
| Or
| Equals
type cste =
| True
| False
| Int of int
type exp =
| Let of inst*exp*exp (* lex x = e in e *)
| Letrec of inst*inst*exp*exp (* let rec f x = e in e *)
| Fun of inst*exp (* fun x -> e *)
| Appl of exp*exp (* e e *)
| Oper of oper*exp*exp (* e + e*)
| Cond of exp*exp*exp (*if e1 then e2 else e3*)
| Inst of inst
| Cste of cste
let printCste c = match c with
| True -> printf " True "
| False -> printf " False "
| Int i -> print_int i
let printOper o = match o with
| Plus -> printf " + "
| Minus -> printf " - "
| Times -> printf " * "
| And -> printf " && "
| Or -> printf " || "
| Equals -> printf " = "
let rec printExp s = match s with
| Cste c -> printCste c
| Inst i -> print_string i
| Oper (o,e1,e2) -> print_string "(";printExp e1;printOper o;printExp e2;print_string ")";print_newline ()
| Appl (e1,e2) -> print_string "App ";
printExp e1;
printExp e2;
print_newline ()
| Fun (i,e) -> print_string ("fun "^i^" -> ");
printExp e;
print_newline ()
| Letrec (i1,i2,e1,e2) -> print_string ("let rec "^i1^" "^i2^" = ");
printExp e1;
printf " in@.";
printExp e2;
print_newline()
| Let (i,e1,e2)-> print_string ("let "^i^" = ");
printExp e1;
printf " in@.";
printExp e2;
print_newline ()
| Cond (e1,e2,e3)-> printf "if@. ";
printExp e1;
printf " @.then@. ";
printExp e2;
printf " @.else@. ";
printExp e3;
print_newline ()