Bonjour

J'ai trouvé 1 script flex bison que je cherche à comprendre et exécuter

main.ccp
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
// section1: declaration, option parametres (settings)
//----------------------------------------------------
%{
// declaraction de variables
int chars = 0;
int words = 0;
int line = 0;
%}
 
%%
 
// section 2: liste de motifs (pattern) et d'action
//--------------------------------------------------
// motif/pattern				action: c code to execute when the pattern mattches
[a-zA-Z]+						{words++; chars += strlen(yytext);}								// strlen(): calculer la longueur de la chaîne de caractères
//matches a word				updated nbr of words and characters seen
//								yytext:	- variable
//										- point to the input text that the pattern just matched
\n								{chars++; lines++;}
// matches a new line			updates the number of lines and characteres
.								{chars++;}
// regex dot <=> any character
 
// each pattern at the beginning of a line
// flex considers any line that starts with whitespace to be code to be copied into the generated c program
 
%%	// separateur de section
 
// section3: code c
//-----------------
int main( int argc, char* args[] )
{
	yylex();	// La compilation d'une source flex produit une fonction yylex(). Un appel de yylex() déclanche une analyse lexicale du flux yyin
	printf("%8d%8d%8d\n", lines, words, chars);
	return 0;
}
quand je le lance dans visual studio code le message d'erreur suivant apparaît:
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
main2.cpp:1:1: error: expected unqualified-id before '%' token
    1 | %{
      | ^
main2.cpp:8:1: error: 'LETTRE' does not name a type
    8 | LETTRE   [a-zA-Z]
      | ^~~~~~
main2.cpp:10:18: error: expected unqualified-id before '+' token
   10 | MOT      {LETTRE}+
      |                  ^
main2.cpp:11:19: error: expected unqualified-id before '+' token
   11 | NOMBRE   {CHIFFRE}+
      |                   ^
main2.cpp:16:15: error: 'total' does not name a type
   16 |     {NOMBRE}  total+= atoi( yytext );
      |               ^~~~~
main2.cpp:17:5: error: expected unqualified-id before '{' token
   17 |     {MOT}     if (yyleng > score){
      |     ^
main2.cpp:17:15: error: expected unqualified-id before 'if'
   17 |     {MOT}     if (yyleng > score){
      |               ^~
main2.cpp:21:6: error: expected unqualified-id before '.' token
   21 |      .        printf("\nNi mot, ni nombre :%s", yytext);
      |      ^
main2.cpp:22:5: error: expected unqualified-id before '%' token
   22 |     %%
      |     ^
Pouvez vous m'aider?
Cordialement