There is a warning that I could not get rid of it from this code. And this is the code that I could provide :
%{
#include <stdlib.h>
#include <stdio.h>
#include "y.tab.h"
%}
%%
[1-9]+ {
yylval.iVal = atoi(yytext);
printf("NUMBER\n");
return NUMBER;
}
[a-z] {
printf("VARIABLE\n");
yylval.cVal = yytext;
return VARIABLE;
}
[-()<>=+/*\n] {
printf("OPERATOR\n");
return *yytext;
}
"^" {
printf("POW\n");
return *yytext;
}
[ \t]+ ; // Skip whitespaces.
. yyerror("Unknown character.\n");
%%
int yywrap(void)
{
return 1;
}
I got the warning on this part : yylval.cVal = yytext;. How could it go wrong? Thanks in advance.
yylval.cVal? How were we supposed to guess that? The trouble is that the types ofyylval.cValandyytextare not compatible. Sinceyytextis either an array or a pointer (so on the RHS of an assignment, it is treated as a pointer either way), presumablyyylval.cValis a non-pointer type. Maybe you wantedyylval.cVal = yytext[0];? Or maybe you really need to duplicate the string and fix the type ofyylval.cVal.