bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

%lex-param only takes plain names (no -> or . expression)


From: Johannes Dewender
Subject: %lex-param only takes plain names (no -> or . expression)
Date: Tue, 18 Feb 2014 19:17:51 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0



Hello,

I am building a reentrant parser with bison 3.0.2 and flex 2.5.37
(also using name-prefixes, if that makes a difference).
I need to hand yylex a scanner (type yyscan_t) and yyparse some user-defined context (which includes the scanner).

So I don't want to give yyparse the scanner directly as a parameter but as ctxt->yyscanner (which is of type yyscan_t).
Giving the scanner as an additional parameter would be redundant.

What I would like to do:

%name-prefix "dot_"
%define api.pure full
%lex-param      {yyscan_t ctxt->yyscanner}
%parse-param    {context_struct *ctxt}
...
%code requires {
...
struct context_struct {
    yyscan_t yyscanner;
    ...
};
...
dot_parse(&parser_context);

However bison doesn't use "ctxt->yyscanner" and falls back to calling
yylex (&yylval, yyscanner)
and complains
error: 'yyscanner' was not declared in this scope
       yychar = yylex (&yylval, yyscanner);

So what I do is:

%define api.pure full
%lex-param      {yyscan_t ctxt_yyscanner}  /* note _ instead of -> */
%parse-param    {context_struct *ctxt}

%{
...
#define ctxt_yyscanner ctxt->yyscanner


However, this is probably a bit "hacky" compared to how it used to work with
#define YYLEX_PARAM ctxt->yyscanner
(without additional %lex-param)


Another option I have found is using an intermediate lex function accepting a context and calling the "real" yylex with ctxt->yyscanner:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=6d2a9220b832d9a0c0cf35fcc5b9de1542af267d

Though that doesn't sound much better as an option.

Is there a reason why %lex-param only accepts identifiers and no expressions?


greetings
JonnyJD



reply via email to

[Prev in Thread] Current Thread [Next in Thread]