diff --git a/TODO b/TODO index 353cd32..d64e677 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,5 @@ # Parseur - - tests divers et variés - - support pour un point-virgule optionel en fin de nœud - - ajout des flottants (= réels) - - ajout de pre, ->, fby, automates + - ajustement des automates # ... diff --git a/beamer/code/example_automaton.lus b/beamer/code/example_automaton.lus index b0a7aa4..d1dcd94 100644 --- a/beamer/code/example_automaton.lus +++ b/beamer/code/example_automaton.lus @@ -1,12 +1,12 @@ node auto (i: int) returns (o : int); -var x, y:int; +var x, y: int; let automaton | Incr -> do (o,x) = (0 fby o + 1, 2); until o < 5 then Decr | Decr -> do (o,x) = diagonal_int(0 fby o); until o > 3 then Incr tel -node auto (i: int) returns (o: int); +node auto (i: int) returns (o : int); var x, y: int; let _s1 = 1 -> (if _s = 1 and o < 5 then 2 else if _s = 2 and o > then 1 else 1); @@ -14,7 +14,7 @@ let tel node auto (i: int) returns (o : int); -var x, y:int; +var x, y: int; let automaton | Incr -> do (o,x) = (0 fby o + 1, 2); until o < 5 then Decr diff --git a/src/ast_to_c.ml b/src/ast_to_c.ml index 610c0ec..de1a54a 100644 --- a/src/ast_to_c.ml +++ b/src/ast_to_c.ml @@ -270,7 +270,7 @@ let cp_equations fmt (eqs, hloc, h) = List.map (fun eq -> equation_to_expression (hloc, h, eq)) eqs in let main_block = remove_ifnot main_block in let main_block = merge_neighbour_ifs main_block in - Format.fprintf fmt "\t/*Main code :*/\n%a" + Format.fprintf fmt "\t/*Main code:*/\n%a" cp_block (main_block, hloc.nt_map) (** [cp_node] prints a single node *) diff --git a/src/cprint.ml b/src/cprint.ml index b1a0dc0..8527b58 100644 --- a/src/cprint.ml +++ b/src/cprint.ml @@ -362,7 +362,7 @@ let cp_main_fn fmt (prog, sts) = else Format.fprintf fmt "%s%a") (match h with | IVar _ -> "%d" - | BVar _ -> "%c" + | BVar _ -> "%hd" | RVar _ -> "%lf") cp_scanf_str (true, t) in @@ -389,7 +389,7 @@ let cp_main_fn fmt (prog, sts) = else Format.fprintf fmt "%s%a") (match h with | IVar _ -> "%d" - | BVar _ -> "%c" + | BVar _ -> "%hd" | RVar _ -> "%f") cp_printf_str (true, t) in @@ -424,13 +424,15 @@ let cp_main_fn fmt (prog, sts) = | Some node -> Format.fprintf fmt "int main (int argc, char **argv)\n\ {\n%a\n\ - \tchar _buffer[1024];\n\ + \t#define BUFFER_SIZE 1024\n\ + \tchar _buffer[BUFFER_SIZE];\n\ \tt_state_main state;\n\ \tstate.is_init = true;\n\ \tstate.is_reset = false;\n\ \twhile(true) {\n\ - \t\tfor(int idx = 0; idx < 1024; idx++) {\n\ - \t\t\tif(idx == 1023 || (_buffer[idx] = getchar()) == '\\n') {\n\ + \t\tprintf(\"input: \");\n\ + \t\tfor(unsigned short idx = 0; idx < BUFFER_SIZE; idx++) {\n\ + \t\t\tif(idx == (BUFFER_SIZE - 1) || (_buffer[idx] = getchar()) == '\\n') {\n\ \t\t\t\t_buffer[idx] = '\\0';\n\ \t\t\t\tbreak;\n\ \t\t\t}\n\ @@ -438,7 +440,9 @@ let cp_main_fn fmt (prog, sts) = \t\tif(!strcmp(_buffer, \"exit\")) { break; }\n\ \t\tsscanf(_buffer, %a);\n%a\ \t\tfn_main(&state, %a);\n\ + \t\tprintf(\"output: \");\n\ \t\tprintf(%a);\n\ + \t\tprintf(\"\\n\");\n\ \t}\n\ %a\treturn EXIT_SUCCESS;\n\ }\n" diff --git a/tests/arrow.node b/tests/arrow.node new file mode 100644 index 0000000..cb98c2b --- /dev/null +++ b/tests/arrow.node @@ -0,0 +1,4 @@ +node main (i: int) returns (o: int); +let + o = 1 -> 2 -> 3; +tel diff --git a/tests/test.node b/tests/automaton.node similarity index 100% rename from tests/test.node rename to tests/automaton.node diff --git a/tests/counting.node b/tests/counting.node new file mode 100644 index 0000000..b226c53 --- /dev/null +++ b/tests/counting.node @@ -0,0 +1,16 @@ +-- count the number of top between two tick +node counting (tick:bool; top:bool) +returns (o: int); +var v, o1: int; +let o = if tick then v else 0 -> (pre o) + v; + v = if top then 1 else 0 +tel; + +node main (i: int) +returns (o: int); +let + -- 0 means no `tick` and no `top` + -- 1 means `tick` + -- 2 means `top` + o = counting(i = 1, i = 2) +tel; diff --git a/tests/test_pre.node b/tests/pre.node similarity index 58% rename from tests/test_pre.node rename to tests/pre.node index 7f30528..2cf9d7c 100644 --- a/tests/test_pre.node +++ b/tests/pre.node @@ -1,4 +1,4 @@ -node n2 (i: int) returns (o: bool); +node main (i: int) returns (o: bool); let o = pre (true and pre( i = pre(pre(i)))); tel diff --git a/tests/reset.node b/tests/reset.node new file mode 100644 index 0000000..31556a7 --- /dev/null +++ b/tests/reset.node @@ -0,0 +1,15 @@ +-- counter of `top`s until `reset` condition holds +node counting (tick: bool) returns (o: int); +var v: int; +let + o = v -> (pre o) + v; + v = if tick then 1 else 0 +tel + +node main (i: int) returns (o: int); +let + -- 0 means no `top` and no `reset` + -- 1 means `top` + -- 2 means `reset` + o = reset counting(i = 1) every (i = 2); +tel diff --git a/tests/test2.node b/tests/tuple.node similarity index 100% rename from tests/test2.node rename to tests/tuple.node diff --git a/tests/when_merge.node b/tests/when_merge.node new file mode 100644 index 0000000..c93cde0 --- /dev/null +++ b/tests/when_merge.node @@ -0,0 +1,14 @@ +node test (i: int) returns (o: int); +var x, y: int; +let + x = (1 / i) when (i <> 0); + y = 0 when (not (i <> 0)); + o = merge (i <> 0) x y; +tel + +node main (i: int) returns (o: int); +var garbage: int; +let + garbage = test(0); + o = test(1); +tel