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 06:35:37 -0700
User-agent: Roundcube Webmail/0.9.2

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

If we translate parser.y with "bison --yacc -d" to generate a y.tab.h and y.tab.c,
the y.tab.h contains:

 int yyparse (private_context *ctx);

I think that adding

%code requires
{
  struct private_context;
}

Hi Akim,

The example I gave is (to my best knowledge and effort)
POSIX-conforming Yacc code. I refer to the specification:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/yacc.html

I don't see %code in the POSIX specification.

This means that the code has gone from breaking on Bison
to only working on Bison.

should suffice to address your concern.  This will add this forward
definition before the declaration of yyparse in the header.

While on the topic of POSIX, what does it have to say about
the y.tab.h header file?

  -d  Write the header file; by default only the code
      file is written. The #define statements associate the
      token codes assigned by yacc with the user-declared
      token names. This allows source files other than
      y.tab.c to access the token codes.

According to this, y.tab.h is supposed to just #define
the token codes!

(Unfortunately, the spec forgets the obvious: that lexers
also need YYSTYPE from y.tab.h, and traditional Yacc
implementations provide it.)

In any case, users who want who want additional declarations
can easily write their own header like "y.decl.h". The
%code functionality for depositing additional material in
y.tab.h is superfluous, solving a problem that is already
solved by the C preprocessor, and the fact that you can
#include your own header between %{ and %} in the grammar
file. Anyone who has needed a global declaration for yyparse
(or anything else exported by the .y file) in the past 40
years probably did exactly that.





reply via email to

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