I am trying to create a reentrant parser using flex and bison.
I want to add a parameter to save some state, but I failed to add it to yylex()
.
Here is the example, it is not expected to compile, just shows the generated code.
foo.l
%option reentrant
%option bison-bridge
%option header-file="foo.tab.h"
%{
#include "foo.tab.h"
%}
%%
"{" { return "{"; }
")" { return '}'; }
%%
foo.y
%define api.pure full
%define parse.error verbose
%parse-param {void *scanner}
%parse-param {int *pint}
%lex-param {void *scanner}
%lex-param {int *pint}
%token '(' ')'
%%
foo : '(' | ')' ;
%%
run with:
bison -d -b foo foo.y
flex foo.l
gcc -E lex.yy.c | less
We can see int yylex (YYSTYPE * yylval_param , yyscan_t yyscanner) {...}
So pint
is gone. But I think I have specified it at foo.y
. So what I need to do more to make yylex accept pint?
Environment: Gentoo Linux stable with Bison-3.0.4 and Flex 2.5.39