bug-bison
[Top][All Lists]
Advanced

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

Re: yyparse being prototyped in y.tab.h causes problems.


From: Kaz Kylheku
Subject: Re: yyparse being prototyped in y.tab.h causes problems.
Date: Tue, 18 Aug 2015 13:43:22 -0700
User-agent: Roundcube Webmail/0.9.2

On 18.08.2015 12:40, Akim Demaille wrote:
Le 18 août 2015 à 16:40, Kaz Kylheku <address@hidden> a écrit :

On 18.08.2015 06:35, I blundered:
Hi Akim,
The example I gave is (to my best knowledge and effort)
POSIX-conforming Yacc code.

Hi Akim, and everyone,

Sorry for the above nonsense; of course it obviously is
not due to the

 %pure-parser
 %parse-param{private_context *ctx}

which is important to the issue!

If you use an extension, then the yacc implementation
can put whatever it wants in y.tab.h, of course;
conformance has largely gone out the window.

Though not standard, %pure-parser and %parse-param are implemented by other parser generators, though, like Berkeley Yacc. (Because reentrant parsing is a very
important extension!)

On the other hand, %code doesn't port to byacc:

 byacc: e - line 10 of "test.y", syntax error
 %code { abc }
 ^

Well, in that case I would include the forward declaration of your
struct in file that include your *.tab.h.

For my circular ref problem, there can be indeed a solution like this,
whereby we split the header file:

  /* parser_prologue.h */
  struct parser_context;

  /* parser_epilogue.h */
  typedef struct parser_context {
    YYSTYPE member;
  };

Then elsewhere (including the Yacc file) we do:

  #include "parser_prologue.h"
  #include "y.tab.h"
  #include "parser_epilogue.h"

And of course the %parser-param declaration in the Yacc file must
use the struct type, not the typedef name, so that y.tab.h
ends up with:

  int yyparse(struct parser_context *);

The only problem is that this is somewhat messy, and
not necessary with Bison 2.x or Byacc.

I addressed the issue in my project with a two-liner in the
Makefile which scrubs the yyparse declaration from y.tab.h
using sed, so I don't care about this any more.



reply via email to

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