diff options
Diffstat (limited to 'parser.ml')
-rw-r--r-- | parser.ml | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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 | ||
23 | let program_of_string str = | 23 | (* FIXME: reject multiple definition of a single register *) |
24 | let lex = Str.split (Str.regexp "[\t\n(),]+") str | 24 | let 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 | |||
29 | let seq_from_string lexer_func str = Str.split (Str.regexp "[\t\n(), ]+") str |> lexer_func | ||
30 | let program_of_string = seq_from_string program_of_lex | ||
31 | let regs_of_string = seq_from_string regs_of_lex | ||
26 | 32 | ||