bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] more on prologue alternatives


From: Paolo Bonzini
Subject: Re: [PATCH] more on prologue alternatives
Date: Wed, 04 Oct 2006 09:05:06 +0200
User-agent: Thunderbird 1.5.0.7 (Macintosh/20060909)

> What if the user doesn't have a %union?
> You place your %{...%} or %header { ... } block *after the %%*, in the grammar
> section.

You said that maps to before the header or the beginning of the header, so
that wouldn't work, right?

No, after %% and after %union is the same.  But I may as well withdraw
my patch, read on.

> Java will not use %union in fact, but it needs to have "%{...%}"
> after the %% to declare parser methods.

As I understand it (but I'm not a Java expert), before vs. after and start
vs. end is pretty much irrelevant in Java.  That is, the compiler figures
out forward references for you.  So, as far as I can tell, you only need
to care about header vs. code file, right?

Well, you could say that you need only two instead of three: in my case it
is "outside the parser class" (e.g. for imports) and "inside" (for
methods used in the actions).  But they don't really map to header/code,
so I'm using %{...%} respectively before/after %%.

> >   %start-header { #include "type1.h" }
> >   %union { type1 field1; }
> >   %destructor { type1_destroy ($$); } <type1>
> >
> >   %start-header { #include "type2.h" }
> >   %union { type2 field2; }
> >   %destructor { type2_destroy ($$); } <type2>

Modularity.  I think the user should have more flexibility in how to
organize his grammar file.  I don't see the above as scattered.  I see it
as organized by type.

That's a different point of view.  I can't but accept that there are
other points of view! :-)

Just out of curiosity, how would the following proposal
(mentioned somewhere in that thread) work for you?  We would make the
following changes to the %*-header directives:

1. Change %after-header{...} to %code{...}.  This is where you put most
code for the code file.

2. Change %end-header{...} to %header-code{...}.  This is where you put
most code for the header file.

So far so good.

3. Change %start-header{...} to %type-code{...}.  For C/C++ users, this is
the right place to put any code that is required by YYSTYPE or YYLTYPE. You probably don't need it in Java, but you could use it if you'd like to
organize your output.

I don't like the %type-code name (constructive criticism in a couple
of paragraphs!).

4. Remove %before-header entirely.  We're not sure it's actually
necessary.

I would put #include directives for the parser
there in C (e.g. <stdlib.h>), since %before-header IIRC is just good
old %{...%}.  But in the end putting them in %after-header wouldn't be
a problem, right?

For Java I need only one of %start-header and %before-header, and only
one of %end-header and %after-header.  I'd choose the one that is more
language-neutral, so I'm very much okay with just renaming the
directives.

A renaming proposal working for me would be %after-header -> %code, and
%before-header -> %prolog, and likewise %header-code and %header-prolog.
This, plus letting these appear in the grammar section, would be just
perfect.  I think it would keep the "coherency/symmetry" idea of my
patch, and all the flexibility of CVS Bison.

Paolo




reply via email to

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