aboutsummaryrefslogtreecommitdiff
path: root/parser.ml
diff options
context:
space:
mode:
Diffstat (limited to 'parser.ml')
-rw-r--r--parser.ml12
1 files changed, 9 insertions, 3 deletions
diff --git a/parser.ml b/parser.ml
index 72042d2..1f367d1 100644
--- a/parser.ml
+++ b/parser.ml
@@ -20,7 +20,13 @@ let rec program_of_lex = function
20 | "jump" :: arg_1 :: arg_2 :: arg_3 :: tail -> (Jump ((int_of_string arg_1), (int_of_string arg_2), (int_of_string arg_3))) :: (program_of_lex tail) 20 | "jump" :: arg_1 :: arg_2 :: arg_3 :: tail -> (Jump ((int_of_string arg_1), (int_of_string arg_2), (int_of_string arg_3))) :: (program_of_lex tail)
21 | _ -> raise Syntax_error 21 | _ -> raise Syntax_error
22 22
23let program_of_string str = 23(* FIXME: reject multiple definition of a single register *)
24 let lex = Str.split (Str.regexp "[\t\n(),]+") str 24let rec regs_of_lex = function
25 in List.iter (fun s -> print_string s; print_newline ()) lex; program_of_lex lex 25 | [] -> []
26 | regnum :: regvalue :: tail -> Reg (int_of_string regnum, int_of_string regvalue) :: (regs_of_lex tail)
27 | _ -> raise Syntax_error
28
29let seq_from_string lexer_func str = Str.split (Str.regexp "[\t\n(), ]+") str |> lexer_func
30let program_of_string = seq_from_string program_of_lex
31let regs_of_string = seq_from_string regs_of_lex
26 32