-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ml
49 lines (36 loc) · 1.24 KB
/
main.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
open ULang
open Lexer
open Parser
open Arg
open Printf
let parseProgram c =
try let lexbuf = Lexing.from_channel c in
parser_main lexer_main lexbuf
with Parsing.Parse_error -> failwith "Program Parse failure!" ;;
let parseInputs c =
try let lexbuf = Lexing.from_channel c in
parser_inputs lexer_inputs lexbuf
with Parsing.Parse_error -> failwith "Input Parse failure!" ;;
let arg = ref stdin in
let inputs = ref stdin in
let setProg p = arg := open_in p in
let usage = "Usage: ./main PROGRAM_FILE" in
parse [] setProg usage ;
let parsedProg = parseProgram !arg in
(* let () = print_string "Program Parsed" ; print_newline() in *)
let parsedInputs = parseInputs !inputs in
(* let () = print_string "Inputs Parsed" ; print_newline() in *)
let rec typeCheck e =
match e with
| [] -> ()
| hd::tl -> typeOf hd; typeCheck tl in
let () = typeCheck parsedProg in
let () = ULang.evalInputs parsedInputs in
let result = ULang.eval parsedProg in
(* let () = print_string "Program Evaluated to ==> " ; print_res result ; print_newline() in *)
let rec print_results res =
match res with
| [] -> ()
| hd::tl -> ULang.print_res hd; print_newline(); print_results tl in
print_results result;
flush stdout