bison-patches
[Top][All Lists]
Advanced

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

Re: glr: include the created header


From: Joel E. Denny
Subject: Re: glr: include the created header
Date: Mon, 19 Dec 2005 16:07:15 -0500 (EST)

On Mon, 19 Dec 2005, Akim Demaille wrote:

> >>> "Joel" == Joel E Denny <address@hidden> writes:
> 
>  > On Sat, 3 Dec 2005, Akim Demaille wrote:
>  >> Le 3 d?c. 05 ? 02:44, Joel E. Denny a ?crit :
>  >> 
>  >>> Did you intend for b4_pre_prologue to appear in
>  >>> b4_shared_declarations? I didn't expect to see my prologues in my
>  >>> header file.  This can lead to unexpected pollution of the
>  >>> namespace of the #includer, and it's inconsistent with yacc.c at
>  >>> least.
>  >> 
>  >> Yes I did, because the pre-prologue is expected to define what
>  >> yystype needs, and the latter is export in the header file.  Actually,
>  >> that's something I wish I could also change in yacc.c...
> 
>  > I can see the logic in this feature, but I think it's a bit cryptic. 
>  > Even more confusing since it's inconsistent with yacc.c.
> 
> I would have like yacc.c to follow this pattern too.  I find this
> logical.

I agree that it's logical... once you've read about it and assuming you 
haven't forgotten it.  However, I fear that many parser developers will 
never think about the %union dependencies, their parsers will magically 
compile, and they'll have stuff in their headers that shouldn't be there 
until their users complain of conflicts.

I believe that requiring a %union-dependencies would make bison specs more 
readable with no such unexpected side effects.  The only mistake would be 
forgetting it, and then the parser developer's compiler would complain 
before he ever released his code to his users.

To put it another way, for the header file, the pre-prologue seems like an 
unexpected hidden declaration while %union-dependencies would be an 
explicit declaration.

>  >> If you don't want them to be exported, they should probably be
>  >> in the post-prologue.  Is that ok with you?
> 
>  > That's a problem because sometimes I either don't define %union or
>  > I define it with #define YYSTYPE (in a header file with its
>  > dependencies).  In those cases, is there any way to avoid having
>  > all of my literal blocks dumped into the header file?
> 
> Bummer.  You are right, in this case the pre-prologue should be the
> post-prologue.  Do you see a problem if that's implemented in Bison
> that way?

That would allow my code to work.

>  > Why not add a %union-dependencies declaration?  Its code could be
>  > placed in the shared dependencies.  The pre-prologue and
>  > post-prologue could sit outside but in the usual sequence.  This
>  > should be backward-compatible, easier to understand, and compatible
>  > with yacc.
> 
> I fear the introduction of zillions of %directives.

I understand that point.  In this particular case, I believe it's a 
worthwhile tradeoff. Even after this long discussion, I fear *I* may 
sometimes forget to place my %union before all literal blocks that it 
doesn't depend on.

Another possibility is to require the user to handle %union dependencies 
himself.  I often #define YYSTYPE in a YYSTYPE.h that contains its 
dependencies.  I then #include YYSTYPE.h in a literal block.  In the 
scanner, I #include YYSTYPE.h and parser.tab.h.  This is the only way to 
handle non-trivial YYLTYPE definitions right now anyway, right?

Joel

reply via email to

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