This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intereval.ml
82 lines (68 loc) · 2.91 KB
/
intereval.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
(************************************************************************
* *
* MASTER STL M1 anne'e 2005/06 *
* *
* Cours Compilation Avanceels *
* *
* Compilation -> Langage intermediaire *
* *
* partie de ml2java *
* *
************************************************************************
* *
* intereval.ml : interprère interactif *
* *
* version : $Version$ $Date: 2006/05/01 15:35:26 $ *
* *
* auteur : Emmanuel Chailloux *
* *
************************************************************************)
open Types;;
open Alex;;
open Asyn;;
open Typeur;;
open Env_typeur;;
open Intertypeur;;
open Eval;;
open Env_eval;;
open Printexc;;
let main () =
try
let lexbuf = Lexing.from_channel stdin in
while true do
try
print_string "$ ";flush stdout;
let result = Asyn.implementation Alex.main lexbuf in
begin
match result with
Expr e -> let v,qt = type_check_and_eval e in
begin print_string "- : "; print_quantified_type qt;
print_string " = "; print_ml_val v;
print_newline(); flush stdout
end
| Decl (Let(b,s,e)) ->
let e =
if not b then e
else (Letin(b,s,e,Var s)) in
begin
let v,qt = type_check_and_eval e in
print_string (s^" : "); print_quantified_type qt;
print_string " = ";print_ml_val v;
print_newline(); flush stdout;
initial_typing_env:=(s,qt)::!initial_typing_env;
initial_eval_env:=(s,v)::!initial_eval_env;
end
end
with Failure "type_check" -> ()
| Failure s -> print_string ("Exception "^(s)^" non recuperee")
| Eval_failure s -> print_string ("Argument invalide "^s);print_newline()
| Toplevel -> ()
done
with End_of_file -> ();;
print_string "Master STL - M1 - Module CA - 2005/2006 ";
print_newline();;
print_newline();;
print_string "evaluateur d'un mini-ML";;
print_newline();;
print_newline();;
main();;