In the absence of a declaration, %union bison defines YYSTYPE as int, so all Character Values ββare integers. In fact, you have several solutions for this problem:
1) yylval solution | union (RECOMMENDED):
As you know, yylval is a global variable used by lexer to store the yytext variable ( yylval = yytext; ), so you must tell your lexer which types you want to store. You can simply add this line to the heading of your YACC grammar:
#define YYSTYPE char *
you only save string values ββhere.
By the way, if you want to store different types, you must specify yacc in your file:
%union { char *a; double d; int fn; }
then in your lex you will have
[a-zA-Z0-9]+ { **yylval.a** = yytext; return ALPHANUM; }
2) Using yytext:
Tip: for callbacks after the rules in yacc, I personally prefer to use functions. not all code like you :)
this solution is really simple. Sentence: "Sphere("{callback_your_function(yytext);} ALPHANUM ")."
yytext here will have the value of your ALPHANUM token, because this is the next token.
source share