Bonjours
Quelqu’un peut –il m’aider ?
Dans le cadre d’un TP de langage de formel et compilation, il nous a été demandé de créer un analyseur syntaxique de notre propre langage sous flex et bison.
Voici le fichier Flex et bison ainsi que les commandes pour lier flex et bison et pour le compiler.
Flex :
Bison :
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 %{ #include <string.h> #include <stdlib.h> #include "calc.tab.h" %} chiffre [0-9] ID [a-z][a-z0-9]* %% {chiffre}+ { yylval.intval=atoi(yytext); return(NOMBRE); } faire { return(FAIRE);} sinon { return(SINON);} fin { return(FIN);} si { return(SI); } entier { return(ENTIER);} debut { return(DEBUT);} lire { return(LIRE); } alors { return(ALORS);} tantque { return(TANTQUE);} ecrire { return(ECRIRE);} {ID} { yylval.id=(char *) strdup(yytext); return(IDENTIFICATEUR);} [ \t\n]+ { return(yytext[0]); } %% int yywrap(void) {}
Et les commandes :
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 %{ #include <stdio.h> #include <stdlib.h> #include <string.h> %} %union { int intval; char *id; } %start program %token <intval> NOMBRE %token <id> IDENTIFICATEUR %token SI TANTQUE ALORS SINON FAIRE DEBUT FIN ENTIER LIRE ECRIRE %left "-" "+" %left "*" "/" %right "^" %% program:DEBUT corps FIN ; corps:liste_declaration liste_instruction ; liste_declaration: | declaration";"liste_declaration ; declaration: ENTIER IDENTIFICATEUR ; liste_instruction: |instruction";"liste_instruction ; instruction: IDENTIFICATEUR"="expression | DEBUT liste_instruction FIN | SI expression ALORS instruction SINON instruction | SI expression ALORS instruction | TANTQUE expression FAIRE instruction | ECRIRE liste_argument | LIRE IDENTIFICATEUR ; liste_argument: | expression | expression ";"liste_argument ; expression:expression"<"expression_simple |expression">"expression_simple |expression"=="expression_simple |expression"!="expression_simple |expression"<="expression_simple |expression">="expression_simple |expression_simple ; expression_simple:expression_simple"+"terme |expression_simple"-"terme |"("expression_simple")" |terme |"-"terme ; terme:terme"*"facteur |terme"/"facteur |terme"^"facteur |facteur ; facteur:IDENTIFICATEUR|NOMBRE ; %% int yyerror(char *s) { printf("%s\n",s); } int main(void) { yyparse(); }
bison -d monfichier.y
flex monfichier.l
gcc -o analyseur lex.yy.c y.tab.c -ll –ly
Ce message apparait lorsque je le compile :
C:\Documents and Settings\Administrateur\Bureau\essai\calc.tab.o:calc.tab.c|| undefined reference to `yylex'|
||=== Build finished: 1 errors, 0 warnings ===|
Aidez moi svp à denicher et à corriger cette erreur
Merci
Partager