-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ml
More file actions
30 lines (26 loc) · 891 Bytes
/
main.ml
File metadata and controls
30 lines (26 loc) · 891 Bytes
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
open Interpreter;;
open Lexer;;
open Parser;;
if Array.length Sys.argv <> 2 then begin
Printf.printf "Usage: %s <input_file>\n" Sys.argv.(0);
exit 0;
end
;;
let init_prog = Parser.program Lexer.token (Lexing.from_channel (open_in Sys.argv.(1)));;
let counter = ref 1;;
let new_prog = modifyInitialProg init_prog 1;;
Printf.printf "%s Loaded Successfully!!\n" Sys.argv.(1);;
try
while (true) do
Printf.printf "%d ?- " !counter;
let line = read_line() in
counter := !counter + 1;
if line = "halt." then exit 0
else try
let goal = Parser.goal Lexer.token (Lexing.from_string line) in
match (interpret_goal goal new_prog) with
(true, _) -> Printf.printf "true.\n"
| (false, _) -> Printf.printf "false.\n";
with e -> Printf.printf "%s\n" (Printexc.to_string e)
done
with _ -> print_string "\n% halt\n"