diff options
author | pacien | 2018-04-30 20:50:28 +0200 |
---|---|---|
committer | pacien | 2018-04-30 20:50:28 +0200 |
commit | a27cc602422cc9076ddc1d0e7db3f3cbf2bf193f (patch) | |
tree | a6e4b168aebdd4807466436a9ba5a58b1ad9e99d /src/main.ml | |
parent | 8e34ad7563ec54b3606fd530da0b4268d662740a (diff) | |
download | urm-a27cc602422cc9076ddc1d0e7db3f3cbf2bf193f.tar.gz |
Adjust parser
Diffstat (limited to 'src/main.ml')
-rw-r--r-- | src/main.ml | 12 |
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 | |||
8 | open Instptr | 8 | open Instptr |
9 | open Reg | 9 | open Reg |
10 | open Urm | 10 | open Urm |
11 | open Eurm | ||
11 | 12 | ||
12 | let exec_with_resource func filename = | 13 | let 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 | ||
17 | let read_prgm = exec_with_resource (fun f -> string_of_file f |> program_of_string) | 18 | let read_prgm lexer = exec_with_resource (fun f -> string_of_file f |> program_of_string lexer) |
18 | let read_regs = exec_with_resource (fun f -> string_of_file f |> regs_of_string) | 19 | let read_regs = exec_with_resource (fun f -> string_of_file f |> regs_of_string) |
19 | let run run_func prgm regs = urm_mk prgm regs |> run_func |> regs_string |> print_endline | 20 | let 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 | ||
27 | let 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 | |||
26 | let () = match Sys.argv with | 32 | let () = 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>" |