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
%lex-param
) have no influence on flex. How could they? Flex doesn't even know the name of the bison file. – rici%lex-param
automatically add additional args in flex. – OstCollectoryyflex
function, with a defined parameter list.bison
produces code which callsyyflex
, providing an actual argument lust. They are separate tools; they don't see each other's files. But obviously the declaration and the call must agree. So the source files for the two tools need to make sure that both tools generate compatible outputs. – riciyyextra
(rather than modifyingyylex
signature) as explained in the answer to this question and in flex docs. – gudok