diff options
author | pacien | 2018-04-21 16:02:14 +0200 |
---|---|---|
committer | pacien | 2018-04-21 16:02:14 +0200 |
commit | 27fadcf4521b0459975d6b9b02a68181c44b791f (patch) | |
tree | 2fb28df2cb02b902410c1fd109a06f35133fb446 | |
parent | 012ad2b3c060032108e224c3cdd03bf0aa05c818 (diff) | |
download | urm-27fadcf4521b0459975d6b9b02a68181c44b791f.tar.gz |
Make instruction parser case insensitive
-rw-r--r-- | parser.ml | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -13,12 +13,14 @@ let rec string_of_file f = | |||
13 | 13 | ||
14 | let rec program_of_lex = function | 14 | let rec program_of_lex = function |
15 | | [] -> [] | 15 | | [] -> [] |
16 | | "zero" :: arg_1 :: tail -> (Zero (int_of_string arg_1)) :: (program_of_lex tail) | 16 | | instr :: tail -> match (String.lowercase_ascii instr) :: tail with |
17 | | "succ" :: arg_1 :: tail -> (Succ (int_of_string arg_1)) :: (program_of_lex tail) | 17 | | "zero" :: arg_1 :: tail -> (Zero (int_of_string arg_1)) :: (program_of_lex tail) |
18 | | "copy" :: arg_1 :: arg_2 :: tail -> (Copy ((int_of_string arg_1), (int_of_string arg_2))) :: (program_of_lex tail) | 18 | | "succ" :: arg_1 :: tail -> (Succ (int_of_string arg_1)) :: (program_of_lex tail) |
19 | | "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) | 19 | | "copy" :: arg_1 :: arg_2 :: tail -> (Copy ((int_of_string arg_1), (int_of_string arg_2))) :: (program_of_lex tail) |
20 | | _ -> raise Syntax_error | 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 | 22 | ||
22 | let program_of_string str = | 23 | let program_of_string str = |
23 | let lex = Str.split (Str.regexp "[\t\n(),]+") str | 24 | let lex = Str.split (Str.regexp "[\t\n(),]+") str |
24 | in List.iter (fun s -> print_string s; print_newline ()) lex; program_of_lex lex | 25 | in List.iter (fun s -> print_string s; print_newline ()) lex; program_of_lex lex |
26 | |||