Ajout d'un nouveau système de tests, plus compact, et plus de tests aussi.
This commit is contained in:
parent
353e83a805
commit
89b70bed37
@ -9,3 +9,7 @@ byte:
|
|||||||
clean:
|
clean:
|
||||||
ocamlbuild -clean
|
ocamlbuild -clean
|
||||||
rm -f fouine
|
rm -f fouine
|
||||||
|
|
||||||
|
test: all
|
||||||
|
tests/tests.sh
|
||||||
|
.PHONY: all clean test
|
||||||
|
|||||||
@ -33,5 +33,7 @@ rule token = parse (* la "fonction" aussi s'appelle token .. *)
|
|||||||
| "in" { IN }
|
| "in" { IN }
|
||||||
| "fun" { FUN }
|
| "fun" { FUN }
|
||||||
| "->" { MAPSTO }
|
| "->" { 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 *)
|
| eof { raise Eof } (* fin du fichier *)
|
||||||
|
|||||||
@ -13,6 +13,8 @@ open Expr (* rappel: dans expr.ml:
|
|||||||
%token IF THEN ELSE
|
%token IF THEN ELSE
|
||||||
%token FUN MAPSTO
|
%token FUN MAPSTO
|
||||||
%token LET IN
|
%token LET IN
|
||||||
|
%token PVPV
|
||||||
|
%token UNDERSCORE
|
||||||
%token PRINT
|
%token PRINT
|
||||||
%token BAND BOR
|
%token BAND BOR
|
||||||
%token EQ GT LT GTE LTE
|
%token EQ GT LT GTE LTE
|
||||||
@ -20,6 +22,7 @@ open Expr (* rappel: dans expr.ml:
|
|||||||
%token LPAREN RPAREN
|
%token LPAREN RPAREN
|
||||||
%token EOL /* retour à la ligne */
|
%token EOL /* retour à la ligne */
|
||||||
|
|
||||||
|
%left PVPV
|
||||||
%nonassoc LET IN
|
%nonassoc LET IN
|
||||||
%nonassoc FUN MAPSTO
|
%nonassoc FUN MAPSTO
|
||||||
%nonassoc IF THEN ELSE
|
%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 */
|
%left TIMES /* associativité gauche: a*b*c, c'est (a*b)*c */
|
||||||
%nonassoc PRINT
|
%nonassoc PRINT
|
||||||
%nonassoc UMINUS /* un "faux token", correspondant au "-" unaire */
|
%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: */
|
%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") */
|
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 */
|
expression: /* règles de grammaire pour les expressions */
|
||||||
| INT { Const $1 }
|
| INT { Const $1 }
|
||||||
@ -67,11 +75,17 @@ expression: /* règles de grammaire pour les expressions */
|
|||||||
| PRINT expression { PrInt($2) }
|
| PRINT expression { PrInt($2) }
|
||||||
| IF expression THEN expression ELSE expression { ITE($2,$4,$6)}
|
| IF expression THEN expression ELSE expression { ITE($2,$4,$6)}
|
||||||
| LET VAR EQ expression IN expression { LetIn($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) }
|
| FUN VAR MAPSTO expression { Fun($2,$4) }
|
||||||
| MINUS expression %prec UMINUS { Min(Const 0, $2) }
|
| 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:
|
sexpr:
|
||||||
| INT { Const $1 }
|
| INT { Const $1 }
|
||||||
| VAR { Var $1 }
|
| VAR { Var $1 }
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
1+2+3+4*5*(6+7-8)
|
|
||||||
@ -1 +0,0 @@
|
|||||||
3+2*4
|
|
||||||
@ -1 +0,0 @@
|
|||||||
if (5+6=11) then (if 5-9=9 && 3+3=6 then 42 else 5+98) else 4*2
|
|
||||||
@ -1 +0,0 @@
|
|||||||
(fun x -> fun y -> fun x -> x+y*2) 0 19 4
|
|
||||||
@ -1 +0,0 @@
|
|||||||
let x=3 in (let y=x+2 in x+y)
|
|
||||||
@ -1 +0,0 @@
|
|||||||
4+5+(prInt 42+1)
|
|
||||||
8
Rendu0/tests/tests.ml
Normal file
8
Rendu0/tests/tests.ml
Normal 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
8
Rendu0/tests/tests.sh
Executable 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
|
||||||
Loading…
x
Reference in New Issue
Block a user