Ajout d'un nouveau système de tests, plus compact, et plus de tests aussi.

This commit is contained in:
Mysaa 2022-01-25 02:54:47 +01:00
parent 353e83a805
commit 89b70bed37
Signed by: Mysaa
GPG Key ID: 7054D5D6A90F084F
11 changed files with 42 additions and 12 deletions

View File

@ -9,3 +9,7 @@ byte:
clean:
ocamlbuild -clean
rm -f fouine
test: all
tests/tests.sh
.PHONY: all clean test

View File

@ -33,5 +33,7 @@ rule token = parse (* la "fonction" aussi s'appelle token .. *)
| "in" { IN }
| "fun" { FUN }
| "->" { MAPSTO }
| (['a'-'z' 'A'-'Z' '_'])(['a'-'z' 'A'-'Z' '0'-'9' '_'])* as v { VAR (v) }
| "_" { UNDERSCORE }
| ";;" { PVPV }
| (['a'-'z'])(['a'-'z' 'A'-'Z' '0'-'9' '_'])* as v { VAR (v) }
| eof { raise Eof } (* fin du fichier *)

View File

@ -13,6 +13,8 @@ open Expr (* rappel: dans expr.ml:
%token IF THEN ELSE
%token FUN MAPSTO
%token LET IN
%token PVPV
%token UNDERSCORE
%token PRINT
%token BAND BOR
%token EQ GT LT GTE LTE
@ -20,6 +22,7 @@ open Expr (* rappel: dans expr.ml:
%token LPAREN RPAREN
%token EOL /* retour à la ligne */
%left PVPV
%nonassoc LET IN
%nonassoc FUN MAPSTO
%nonassoc IF THEN ELSE
@ -31,7 +34,7 @@ open Expr (* rappel: dans expr.ml:
%left TIMES /* associativité gauche: a*b*c, c'est (a*b)*c */
%nonassoc PRINT
%nonassoc UMINUS /* un "faux token", correspondant au "-" unaire */
/* cf. son usage plus bas : il sert à "marquer" une règle pour lui donner la précédence maximale */
%nonassoc UNDERSCORE /* cf. son usage plus bas : il sert à "marquer" une règle pour lui donner la précédence maximale */
%start main /* "start" signale le point d'entrée: */
@ -44,9 +47,14 @@ open Expr (* rappel: dans expr.ml:
main: /* <- le point d'entrée (cf. + haut, "start") */
expression EOL { $1 } /* on veut reconnaître une expression */
preambule EOL { $1 } /* on veut reconnaître une expression */
;
preambule:
| LET VAR EQ expression PVPV preambule { LetIn($2,$4,$6) }
| LET UNDERSCORE EQ expression PVPV preambule { LetIn("_",$4,$6) }
| expression { $1 }
;
expression: /* règles de grammaire pour les expressions */
| INT { Const $1 }
@ -67,11 +75,17 @@ expression: /* règles de grammaire pour les expressions */
| PRINT expression { PrInt($2) }
| IF expression THEN expression ELSE expression { ITE($2,$4,$6)}
| LET VAR EQ expression IN expression { LetIn($2,$4,$6) }
| LET UNDERSCORE EQ expression IN expression { LetIn("_",$4,$6) }
| FUN VAR MAPSTO expression { Fun($2,$4) }
| MINUS expression %prec UMINUS { Min(Const 0, $2) }
| expression sexpr %prec APP { App($1,$2) }
;
| applic sexpr %prec APP { App($1,$2) }
;
applic:
| applic sexpr { App($1,$2) }
| VAR { Var $1 }
| LPAREN expression RPAREN { $2 }
;
sexpr:
| INT { Const $1 }
| VAR { Var $1 }

View File

@ -1 +0,0 @@
1+2+3+4*5*(6+7-8)

View File

@ -1 +0,0 @@
3+2*4

View File

@ -1 +0,0 @@
if (5+6=11) then (if 5-9=9 && 3+3=6 then 42 else 5+98) else 4*2

View File

@ -1 +0,0 @@
(fun x -> fun y -> fun x -> x+y*2) 0 19 4

View File

@ -1 +0,0 @@
let x=3 in (let y=x+2 in x+y)

View File

@ -1 +0,0 @@
4+5+(prInt 42+1)

8
Rendu0/tests/tests.ml Normal file
View File

@ -0,0 +1,8 @@
1+2+3+4+5*(6+7-8)+7
12+5*6
if (5+6=11) then (if 5-9=9 && 3+3=6 then 33 else 53-11) else 33+54
3+5+(prInt 33+1)
let x=4 in (let y=x+3 in x*y+14)
let x=prInt 33 in let x=25 in x+17
let f=fun x -> x*2 in let x = 12 in f (f x -3)
(fun x -> fun y -> fun x -> x+y*2) 0 19 4

8
Rendu0/tests/tests.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
while IFS="" read -r p || [ -n "$p" ]
do
echo "--------------------------------";
echo "$p"
echo "$p" | ./fouine;
done < tests/tests.ml