Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried the code below but each time I have an error "unrecognized rule" at line 24 just after return 1

Thank you for your help

What I have tried:

%option noyywrap

%{
#include<stdio.h>
%}
lettre [a-z]
chiffre [0-9]
variable {lettre}.{chiffre}

%%
"main()" {printf ("<%s, c est la fonction main \n");}
"{"|"}" {printf ("cest les accolades \n");}
"const"{variable} {printf ("cest une constant et leur nom \n");}
"int" {variable} printf ("cest variable et leur nom\n");}
[-+*/= ()] {printf ("cest les opérations arithmétiques \n");}
[ ,] {printf ("cest les seperateurs\n");}
[^\n]
.+ {printf("erreur ! ")}
%%
int yywrap()
{

return 1;
}
int main()
{
int yylex();
}
Posted
Updated 3-Dec-22 2:51am
Comments
Richard MacCutchan 3-Dec-22 12:55pm    
The statement int yylex(); does not do anything, it just declares yylex as an external function.
Wissem Nhidi 3-Dec-22 14:31pm    
thank you for your answer, I have just corrected and I tested the example below but it always gives me an error, I do not understand where is the error :
main() { int i; int j; int k; int r; i =3 ; j=4 ; k=8 ; r=(i+j)*(i+k/j) ; }
Richard MacCutchan 4-Dec-22 2:55am    
How can we tell if you do not explain what the error is?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900