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: Joel E. Denny
Subject: Re: [PATCH] more on prologue alternatives
Date: Tue, 3 Oct 2006 15:11:33 -0400 (EDT)

On Tue, 3 Oct 2006, Paolo Bonzini wrote:

> > But the dependence on the %union position is one of the key problems I was
> > trying to eliminate.  I don't have time to examine your patch right now,
> > but, if I understand the explanation above, the only way to do the
> > equivalent of %end-header or %after-header is to have a %union.  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?

> 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?  C/C++ is harder.

> > Also, I'd like to see this kind of grammar organization work:
> > 
> >   %start-header { #include "type1.h" }
> >   %union { type1 field1; }
> >   %destructor { type1_destroy ($$); } <type1>
> > 
> >   %start-header { #include "type2.h" }
> >   %union { type2 field2; }
> >   %destructor { type2_destroy ($$); } <type2>
> > 
> > This should be allowed in the definitions or rules section.  If you change
> > %start-header to %header under your proposal, it won't work.
> >   
> Yeah, I understand.  But I wonder if it warrants the needed complexity.  In C,
> I put all my includes at the beginning of the file.  It gives me a quick way
> to see the interfaces I need in the file; I don't see the need to scatter
> #include's here and there in a Bison source code?

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.

> > Thanks for your interest in this problem.  Maybe you'd like to catch up with
> > our latest discussion starting here:
> > 
> >   http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00048.html
> >   
> Already read, and was lost around the end of the thread. :-)

The latest proposal that Paul and I discussed is a bit complicated and 
very low-level.  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.

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.

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




reply via email to

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