I want to use Flex and Bison together. I have declared a union in the bison definition file that I will use in the lexer. Bison produces a .tab.h file that includes the union declaration (see below). I include this .tab.h file in the lexer definition, but the lexer action:
yylval.stringptr = yytext;
causes a compiler error:
lexer.l: In function ‘yylex’:
lexer.l:190: error: request for member ‘stringptr’ in something not a structure or union
Here is a snippet of the .tab.h file:
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 1676 of yacc.c */
#line 9 "parser.y"
char * s;
char * stringptr;
double d;
int i;
/* Line 1676 of yacc.c */
#line 126 "parser.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
Why is yylval not recognized as a structure or union? How should I correct the problem?
PS: I invoked Flex with --bison-bridge