bison-patches
[Top][All Lists]
Advanced

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

Re: prologue alternatives


From: Joel E. Denny
Subject: Re: prologue alternatives
Date: Sat, 16 Sep 2006 02:31:34 -0400 (EDT)

On Fri, 15 Sep 2006, Paul Eggert wrote:

> However, if you say YYLTYPE works for you, perhaps I'm being too picky
> about it.

Or perhaps I'm not being picky enough.

> I don't follow the second ("more importantly") point.  Distinguishing
> between %stype-code and %ltype-code means we'll have to educate the
> user about these problems anyway.

I was thinking we wouldn't have to, but maybe I'm wrong.

> This extra education complicates
> things just as much (if not more so) as saying "If you want YYSTYPE to
> depend on YYLTYPE you'll have to define both".

I don't know what's complicated to other users.

> As a sometime user of Bison (and as someone who inflicts it on
> students :-) I don't want to have to explain a lot of twisty
> directives that are all slightly different.  I want just one
> directive.  Even if it's not perfect, it's often better than lots of
> little directives that I can't keep straight in my head.

Let's agree to keep %start-header, which is fine with me.  Perhaps simply 
renaming it to %type-code is enough to make it not seem so low-level, 
which was my goal with %stype-code and %ltype-code anyway.

> > But shouldn't we also handle the case where the user doesn't want to 
> > override YYSTYPE (generated from %union perhaps) or YYLTYPE but does want 
> > to add header definitions that depend on them?
> 
> The user can define a header foo.h that looks like this:
> 
>   #include "y.tab.h"
>   [now, declare header definitions that depend on y.tab.h]
> 
> and the user can then include foo.h instead of y.tab.h.
> So a new directive isn't needed to address this issue.

That isn't equivalent yet because yours doesn't place those "header 
definitions that depend on y.tab.h" in the Bison-generated code file.

Instead, foo.h needs to look something like this:

  #include "y.tab.h"
  #include "bar.h"

bar.h looks like this:

  [now, declare header definitions that depend on y.tab.h]

And a %code (or whatever we call the directive that inserts code into the 
code file) looks like this:

  %code { #include "bar.h" }

I've used the above idiom, but this seems much simpler than all of that:

  %header-code {
    [now, declare header definitions that depend on y.tab.h]
  }

Of course, the user can ignore %header-code and still do it the foobar way 
if he wants.




reply via email to

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