diff options
author | pacien | 2018-04-20 23:32:38 +0200 |
---|---|---|
committer | pacien | 2018-04-20 23:32:38 +0200 |
commit | 3f25710a891dfcd17f597c16dfedf5499bc1bbd6 (patch) | |
tree | 71bec80335de3820994d26c68bb4cc8ca961789a /parser.ml | |
parent | 2e6e365262b7dc072d7ac35ff867f309e3ff784c (diff) | |
download | urm-3f25710a891dfcd17f597c16dfedf5499bc1bbd6.tar.gz |
Modularize everything
Diffstat (limited to 'parser.ml')
-rw-r--r-- | parser.ml | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/parser.ml b/parser.ml new file mode 100644 index 0000000..e01208f --- /dev/null +++ b/parser.ml | |||
@@ -0,0 +1,24 @@ | |||
1 | (* | ||
2 | * UPEM / L3 / Functional programming / Project: URM | ||
3 | * Pacien TRAN-GIRARD, Adam NAILI | ||
4 | *) | ||
5 | |||
6 | open Common | ||
7 | |||
8 | let rec string_of_file f = | ||
9 | try | ||
10 | let str = input_line f | ||
11 | in str ^ " " ^ (string_of_file f) | ||
12 | with End_of_file -> "" | ||
13 | |||
14 | let rec program_of_lex = function | ||
15 | | [] -> [] | ||
16 | | "zero" :: arg_1 :: tail -> (Zero (int_of_string arg_1)) :: (program_of_lex tail) | ||
17 | | "succ" :: arg_1 :: tail -> (Succ (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) | ||
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) | ||
20 | | _ -> raise Syntax_error | ||
21 | |||
22 | let program_of_string str = | ||
23 | 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 | ||