bison-patches
[Top][All Lists]
Advanced

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

Re: proposal: simplify prologue alternatives into %code


From: Joel E. Denny
Subject: Re: proposal: simplify prologue alternatives into %code
Date: Thu, 4 Jan 2007 14:16:21 -0500 (EST)

On Thu, 4 Jan 2007, Paolo Bonzini wrote:

> 
> > If we're going to give the default a name, why have a default at all?
> > Imagine reading a grammar file containing the following two directives:
> > 
> >   %code { CODE }
> > 
> >   %code "methods" { CODE }
> > 
> > They look different, so my intuition says they should do something
> > different, but you're proposing that they do the same thing.
> > 
> > Why do you want to do this?
> 
> I'm ok with no default at all; I figured that *you* had a reason to have a
> default :-)

Yes.  One of the problems with %code, %requires, %provides, and %code-top 
is that there seem to be too many directives to easily learn and remember.  
However, I've noticed that it's easier to explain them when I single out 
%code as the directive the user should consider first when he wants to 
write verbatim code.  That is, he need not worry about the other 
directives until he wants to specify location-sensitive code that does not 
belong at the default location.

I like that my newly proposed syntax reflects this decision tree rather 
than keeping all 4 directives on the same level.  That is, a user would 
start with the unqualified %code.  He would not need to worry about 
picking a location qualifier until he wanted to specify location-sensitive 
code that does not belong at the default location.

> and that anyway you need to give a name to the block (if only for 
> consistency and simplicity).

I think having two forms for the same thing would be less consistent and 
less simple than my proposal.  On the other hand, throwing away the 
default form and having only the named form for it is inconsistent with 
the decision tree I described above, and therefore I don't think it makes 
life any simpler for the user.

> One reason would be that (I'm making up this example in Java, where the
> absence of %union makes everything simpler)
> 
> %{
> %}
> ...
> %code {
> }
> 
> could be an alternative way to say
> 
> %code "imports" {
> }
> ...
> %code "methods" {
> }
> 
> not requiring one to remember the "magic" (and possibly easy to misspell?)
> keywords.

For new skeletons, I've been hoping we could drop %{CODE%} and all its 
conceptual baggage.  I think the following reads nicely:

  %code "imports" {
    import foo;
  }

  %code {
    public static void main(String[] args) {
      Parser parser = new Parser();
      System.exit(parser.parse());
    }
  }




reply via email to

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