aboutsummaryrefslogtreecommitdiff
path: root/src/main.ml
diff options
context:
space:
mode:
authorpacien2018-04-30 20:50:28 +0200
committerpacien2018-04-30 20:50:28 +0200
commita27cc602422cc9076ddc1d0e7db3f3cbf2bf193f (patch)
treea6e4b168aebdd4807466436a9ba5a58b1ad9e99d /src/main.ml
parent8e34ad7563ec54b3606fd530da0b4268d662740a (diff)
downloadurm-a27cc602422cc9076ddc1d0e7db3f3cbf2bf193f.tar.gz
Adjust parser
Diffstat (limited to 'src/main.ml')
-rw-r--r--src/main.ml12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/main.ml b/src/main.ml
index 3e66645..c6a059e 100644
--- a/src/main.ml
+++ b/src/main.ml
@@ -8,13 +8,14 @@ open Parser
8open Instptr 8open Instptr
9open Reg 9open Reg
10open Urm 10open Urm
11open Eurm
11 12
12let exec_with_resource func filename = 13let exec_with_resource func filename =
13 let file = open_in filename in 14 let file = open_in filename in
14 let res = func file in 15 let res = func file in
15 close_in file; res 16 close_in file; res
16 17
17let read_prgm = exec_with_resource (fun f -> string_of_file f |> program_of_string) 18let read_prgm lexer = exec_with_resource (fun f -> string_of_file f |> program_of_string lexer)
18let read_regs = exec_with_resource (fun f -> string_of_file f |> regs_of_string) 19let read_regs = exec_with_resource (fun f -> string_of_file f |> regs_of_string)
19let run run_func prgm regs = urm_mk prgm regs |> run_func |> regs_string |> print_endline 20let run run_func prgm regs = urm_mk prgm regs |> run_func |> regs_string |> print_endline
20 21
@@ -23,7 +24,12 @@ let run_mode_of_string = function
23 | "trace" -> urm_run_trace 24 | "trace" -> urm_run_trace
24 | _ -> failwith "Invalid run mode" 25 | _ -> failwith "Invalid run mode"
25 26
27let lexer_of_string = function
28 | "urm" -> (urm_program_of_lex)
29 | "eurm" -> (fun toks -> eurm_program_of_lex toks |> urm_from_eurm)
30 | _ -> failwith "Invalid lang"
31
26let () = match Sys.argv with 32let () = match Sys.argv with
27 | [| _; "run-tests" |] -> () (* handled in test files *) 33 | [| _; "run-tests" |] -> () (* handled in test files *)
28 | [| _; mode; prgm; regs |] -> run (run_mode_of_string mode) (read_prgm prgm) (read_regs regs) 34 | [| _; mode; lang; prgm; regs |] -> run (run_mode_of_string mode) (read_prgm (lexer_of_string lang) prgm) (read_regs regs)
29 | _ -> print_endline "Usage: urm <run-tests | run <prgmfile> <regfile> | trace <prgmfile> <regfile>>" 35 | _ -> print_endline "Usage: urm <run | trace> <urm | eurm> <prgmfile> <regfile>"