Hi, I am embarrassed about how to get char * when I read a certain token ... I look at different sites and they provide suggestions, but not complete, I mean, for example, the yylval and yytext declaration is missing or how to convert types etc.
What is needed in a .l file? What is needed in a .y file?
What i have
in the .l file:
{WORD} { yylval = strdup(yytext);return T_ValidWord;}
in the .y file:
%union{
char *str;
}
%token<str> T_ValidWord
%%
element:
T_OpenTag T_ValidWord ele1 {printf("%s", $2);}
;
Error:
xml.lex: In function ‘yylex’:
xml.lex:34: error: incompatible types when assigning to type ‘YYSTYPE’ from type ‘char *’
Another thing that confused me: In some places I see
yylval->something = yytext
yylval.something = yytext
yylval = yytext
In the bison manual I’ll tell you that yylval is a macro, I understand that the macro is replaced with text for other text, but in this situation I really do not understand it.
source
share