From 27fadcf4521b0459975d6b9b02a68181c44b791f Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 21 Apr 2018 16:02:14 +0200 Subject: Make instruction parser case insensitive --- parser.ml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/parser.ml b/parser.ml index e01208f..72042d2 100644 --- a/parser.ml +++ b/parser.ml @@ -13,12 +13,14 @@ let rec string_of_file f = let rec program_of_lex = function | [] -> [] - | "zero" :: arg_1 :: tail -> (Zero (int_of_string arg_1)) :: (program_of_lex tail) - | "succ" :: arg_1 :: tail -> (Succ (int_of_string arg_1)) :: (program_of_lex tail) - | "copy" :: arg_1 :: arg_2 :: tail -> (Copy ((int_of_string arg_1), (int_of_string arg_2))) :: (program_of_lex tail) - | "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) - | _ -> raise Syntax_error + | instr :: tail -> match (String.lowercase_ascii instr) :: tail with + | "zero" :: arg_1 :: tail -> (Zero (int_of_string arg_1)) :: (program_of_lex tail) + | "succ" :: arg_1 :: tail -> (Succ (int_of_string arg_1)) :: (program_of_lex tail) + | "copy" :: arg_1 :: arg_2 :: tail -> (Copy ((int_of_string arg_1), (int_of_string arg_2))) :: (program_of_lex tail) + | "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) + | _ -> raise Syntax_error let program_of_string str = let lex = Str.split (Str.regexp "[\t\n(),]+") str in List.iter (fun s -> print_string s; print_newline ()) lex; program_of_lex lex + -- cgit v1.2.3