hello
je viens d'apprendre qlq notion de flex/bison, mon probléme se que je viens d'implementer une partie d'une grammaire arithmetique sous flex/bison et j'amerais que lors de l'insertion d'un mots, afficher si il est de la bonne forme ou erreur s'il ne l'est pas. ex: '1+2-1' accepté, '1+0/7' faut.
syntaxique.y
et dans le lexical:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include <ctype.h> #include <stdio.h> void yyerror (char const * s); %} %start S %token NOMBRE OP_ANS OP_DIFF OP_OR %left OP_ANS OP_DIFF %left OP_OR %% S :Exp; Exp :Exp OP_ANS Exp | Exp OP_DIFF Exp | Exp OP_OR Exp | X; X:NOMBRE; %% void yyerror(char const * s) { printf("Erreur syntaxique : %s\n",s); } int main(int argc, char ** argv) { yyparse(); return 0; }
NOMBRE [0-9]
"+" {return OP_ANS;}
"-" {return OP_DIFF;}
"*" {return OP_OR;}
merci d avance.
Partager