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
|
||||
|
||||
- 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
|
||||
|
||||
# ...
|
||||
|
@ -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
|
||||
|
@ -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 *)
|
||||
|
@ -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"
|
||||
|
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
|
||||
o = pre (true and pre( i = pre(pre(i))));
|
||||
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