Improve and correct IO UI and add tests
This commit is contained in:
parent
ff9da14379
commit
5cabb042fc
5
TODO
5
TODO
@ -1,8 +1,5 @@
|
|||||||
# Parseur
|
# Parseur
|
||||||
|
|
||||||
- tests divers et variés
|
- ajustement des automates
|
||||||
- support pour un point-virgule optionel en fin de nœud
|
|
||||||
- ajout des flottants (= réels)
|
|
||||||
- ajout de pre, ->, fby, automates
|
|
||||||
|
|
||||||
# ...
|
# ...
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
node auto (i: int) returns (o : int);
|
node auto (i: int) returns (o : int);
|
||||||
var x, y:int;
|
var x, y: int;
|
||||||
let
|
let
|
||||||
automaton
|
automaton
|
||||||
| Incr -> do (o,x) = (0 fby o + 1, 2); until o < 5 then Decr
|
| 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
|
| Decr -> do (o,x) = diagonal_int(0 fby o); until o > 3 then Incr
|
||||||
tel
|
tel
|
||||||
|
|
||||||
node auto (i: int) returns (o: int);
|
node auto (i: int) returns (o : int);
|
||||||
var x, y: int;
|
var x, y: int;
|
||||||
let
|
let
|
||||||
_s1 = 1 -> (if _s = 1 and o < 5 then 2 else if _s = 2 and o > then 1 else 1);
|
_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
|
tel
|
||||||
|
|
||||||
node auto (i: int) returns (o : int);
|
node auto (i: int) returns (o : int);
|
||||||
var x, y:int;
|
var x, y: int;
|
||||||
let
|
let
|
||||||
automaton
|
automaton
|
||||||
| Incr -> do (o,x) = (0 fby o + 1, 2); until o < 5 then Decr
|
| Incr -> do (o,x) = (0 fby o + 1, 2); until o < 5 then Decr
|
||||||
|
@ -270,7 +270,7 @@ let cp_equations fmt (eqs, hloc, h) =
|
|||||||
List.map (fun eq -> equation_to_expression (hloc, h, eq)) eqs in
|
List.map (fun eq -> equation_to_expression (hloc, h, eq)) eqs in
|
||||||
let main_block = remove_ifnot main_block in
|
let main_block = remove_ifnot main_block in
|
||||||
let main_block = merge_neighbour_ifs 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_block (main_block, hloc.nt_map)
|
||||||
|
|
||||||
(** [cp_node] prints a single node *)
|
(** [cp_node] prints a single node *)
|
||||||
|
@ -362,7 +362,7 @@ let cp_main_fn fmt (prog, sts) =
|
|||||||
else Format.fprintf fmt "%s%a")
|
else Format.fprintf fmt "%s%a")
|
||||||
(match h with
|
(match h with
|
||||||
| IVar _ -> "%d"
|
| IVar _ -> "%d"
|
||||||
| BVar _ -> "%c"
|
| BVar _ -> "%hd"
|
||||||
| RVar _ -> "%lf")
|
| RVar _ -> "%lf")
|
||||||
cp_scanf_str (true, t)
|
cp_scanf_str (true, t)
|
||||||
in
|
in
|
||||||
@ -389,7 +389,7 @@ let cp_main_fn fmt (prog, sts) =
|
|||||||
else Format.fprintf fmt "%s%a")
|
else Format.fprintf fmt "%s%a")
|
||||||
(match h with
|
(match h with
|
||||||
| IVar _ -> "%d"
|
| IVar _ -> "%d"
|
||||||
| BVar _ -> "%c"
|
| BVar _ -> "%hd"
|
||||||
| RVar _ -> "%f")
|
| RVar _ -> "%f")
|
||||||
cp_printf_str (true, t)
|
cp_printf_str (true, t)
|
||||||
in
|
in
|
||||||
@ -424,13 +424,15 @@ let cp_main_fn fmt (prog, sts) =
|
|||||||
| Some node ->
|
| Some node ->
|
||||||
Format.fprintf fmt "int main (int argc, char **argv)\n\
|
Format.fprintf fmt "int main (int argc, char **argv)\n\
|
||||||
{\n%a\n\
|
{\n%a\n\
|
||||||
\tchar _buffer[1024];\n\
|
\t#define BUFFER_SIZE 1024\n\
|
||||||
|
\tchar _buffer[BUFFER_SIZE];\n\
|
||||||
\tt_state_main state;\n\
|
\tt_state_main state;\n\
|
||||||
\tstate.is_init = true;\n\
|
\tstate.is_init = true;\n\
|
||||||
\tstate.is_reset = false;\n\
|
\tstate.is_reset = false;\n\
|
||||||
\twhile(true) {\n\
|
\twhile(true) {\n\
|
||||||
\t\tfor(int idx = 0; idx < 1024; idx++) {\n\
|
\t\tprintf(\"input: \");\n\
|
||||||
\t\t\tif(idx == 1023 || (_buffer[idx] = getchar()) == '\\n') {\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\t_buffer[idx] = '\\0';\n\
|
||||||
\t\t\t\tbreak;\n\
|
\t\t\t\tbreak;\n\
|
||||||
\t\t\t}\n\
|
\t\t\t}\n\
|
||||||
@ -438,7 +440,9 @@ let cp_main_fn fmt (prog, sts) =
|
|||||||
\t\tif(!strcmp(_buffer, \"exit\")) { break; }\n\
|
\t\tif(!strcmp(_buffer, \"exit\")) { break; }\n\
|
||||||
\t\tsscanf(_buffer, %a);\n%a\
|
\t\tsscanf(_buffer, %a);\n%a\
|
||||||
\t\tfn_main(&state, %a);\n\
|
\t\tfn_main(&state, %a);\n\
|
||||||
|
\t\tprintf(\"output: \");\n\
|
||||||
\t\tprintf(%a);\n\
|
\t\tprintf(%a);\n\
|
||||||
|
\t\tprintf(\"\\n\");\n\
|
||||||
\t}\n\
|
\t}\n\
|
||||||
%a\treturn EXIT_SUCCESS;\n\
|
%a\treturn EXIT_SUCCESS;\n\
|
||||||
}\n"
|
}\n"
|
||||||
|
4
tests/arrow.node
Normal file
4
tests/arrow.node
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
node main (i: int) returns (o: int);
|
||||||
|
let
|
||||||
|
o = 1 -> 2 -> 3;
|
||||||
|
tel
|
16
tests/counting.node
Normal file
16
tests/counting.node
Normal file
@ -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;
|
@ -1,4 +1,4 @@
|
|||||||
node n2 (i: int) returns (o: bool);
|
node main (i: int) returns (o: bool);
|
||||||
let
|
let
|
||||||
o = pre (true and pre( i = pre(pre(i))));
|
o = pre (true and pre( i = pre(pre(i))));
|
||||||
tel
|
tel
|
15
tests/reset.node
Normal file
15
tests/reset.node
Normal file
@ -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
|
14
tests/when_merge.node
Normal file
14
tests/when_merge.node
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user