winflexbison
winflexbison copied to clipboard
Reentrant flex/bison call yylex convention
When I use %option api.pure in parser.y and add #define YYLEX_PARAM pData->scaninfo. The generate file parser.tab.cpp just only #define YYLEX yylex (&yylval) which is not match the lexer.l generate function extern int yylex(YYSTYPE* yylval_param, yyscan_t yyscanner);
here is my sample lexer.l:
%option noyywrap nodefault yylineno never-interactive reentrant bison-bridge
%option nounistd
%option header-file="lexer.flex.h"
%{
#include <stdio.h>
#include "PureData.h"
#include "parser.tab.h" /*reference parser generate tab.h*/
%}
%option extra-type = "struct PureData *"
%%
%{
struct PureData *pData = yyextra;
%}
/* other lex rules */
%%
parser.y:
%define api.pure
%parse-param { struct PureData *pData }
/*%lex-param { pData->scaninfo }*/
%{
#include "PureData.h"
#define YY_NO_UNISTD_H //this is flex bug, unistd.h also include in flex.h
#include "lexer.flex.h"
#define YYLEX_PARAM pData->scaninfo
void yyerror(struct PureData* pData, char const *s);
%}
%union{
int intval;
}
%%
/* other grammar */
%%
void yyerror(struct PureData* pData, char const *s) { }
PureData.h:
class ASTNode{
};
typedef void* yyscan_t;
struct PureData
{
yyscan_t scaninfo;
ASTNode* astRoot;
};
Also I have attempted use %lex-param { pData->scaninfo }, but it generates #define YYLEX yylex (&yylval, scaninfo).
So how can I fix it? My version is win_flexbison 2.4.6/2.5.6.
I only get them by <<flex & bison>> Jobn Levine. Is there any other books or examples about reentrant flex/bison?