Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reentrant flex/bison call yylex convention #34

Open
Wzshun opened this issue Mar 2, 2019 · 0 comments
Open

Reentrant flex/bison call yylex convention #34

Wzshun opened this issue Mar 2, 2019 · 0 comments
Assignees
Labels

Comments

@Wzshun
Copy link

Wzshun commented Mar 2, 2019

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?

@lexxmark lexxmark self-assigned this Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants