I have the following code snippet that I wrote in flex. I need to display this message:
{printf("\n%-20s%-30s%-10s\n", "Lexeme", "Unite lexicale", "Indice");}
First thing after the user input, I tried to find a solution but nothing seems to work.
%{
int i=1;
%}
lettre [a-zA-Z]+
nombre_entier (\+|\-)?[0-9]+
nombre_reel (\+|\-)?[0-9]+\.[0-9]+((e|E)(\-|\+)?[0-9]+)?
id {lettre}({lettre}|[0-9])*
%%
\$ { exit(0);}
[ \t]+ {/*ignorer*/}
\n {i=1;}
ENTIER|REEL {printf("%-20s%-30s%-10d\n",yytext, "Mot_cle", i++);
printf("-----------------------------------------------------\n");}
{id} {printf("%-20s%-30s%-10d\n",yytext, "ID", i++);
printf("------------------------------------------------------\n");}
{nombre_entier} {printf("%-20s%-30s%-10d\n",yytext, "nombre entier", i++);
printf("------------------------------------------------------\n");}
{nombre_reel} {printf("%-20s%-30s%-10d\n",yytext, "nombre reel", i++);
printf("------------------------------------------------------\n");}
\( {printf("%-20s%-30s%-10d\n",yytext, "parenthese ouvrante", i++);
printf("------------------------------------------------------\n");}
")" {printf("%-20s%-30s%-10d\n",yytext, "parenthese fermante", i++);
printf("------------------------------------------------------\n");}
"+"|"-"|"*"|"/" {printf("%-20s%-30s%-10d\n",yytext, "operateur arithmetique", i++);
printf("------------------------------------------------------\n");}
"=" {printf("%-20s%-30s%-10d\n",yytext, "operateur d'affectation", i++);
printf("------------------------------------------------------\n");}
"," {printf("%-20s%-30s%-10d\n",yytext, "Virgule", i++);
printf("------------------------------------------------------\n");}
";" {printf("%-20s%-30s%-10d\n",yytext, "Point virgule", i++);
printf("------------------------------------------------------\n");}
. {printf("%-20s%-30s%-10d\n",yytext, "caractere inconnu", i++);
printf("------------------------------------------------------\n");}
%%
int main(){
printf("Entrez le texte a analyser : \n");
yylex();
return 0;
}
int yywrap(){
return 1;
}
Please help.