[Top][All Lists]

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

Re: FYI: fix %start after first rule

From: Joel E. Denny
Subject: Re: FYI: fix %start after first rule
Date: Thu, 14 Sep 2006 21:17:14 -0400 (EDT)

On Thu, 14 Sep 2006, Akim Demaille wrote:

> >>> "Joel" == Joel E Denny <address@hidden> writes:
>  > 3. In general I think it's easier to evolve Bison when the syntax
>  > analysis of the user grammar file is a separate phase from the
>  > semantic analysis as much as possible.  That is, Bison shouldn't
>  > try to understand user declarations until it has read them all.
> I totally subscribe to this view from the implementation point of
> view.


> Still, I am in favor of having a semantic pass doing a regular
> left to right analysis, where entities are expected to be defined (or
> declared) before being used.

I'm a little surprised to see you say that.  Early on in the %*-header 
discussion you made a comment about the irrelevance of order in modern 
languages.  Perhaps I misunderstood what you meant.

>  > In many cases, I agree that we should encourage a specific coding
>  > style.  Requiring %start to be in the definitions section maybe
>  > always makes sense.  I won't argue if we change parse-gram.y
>  > accordingly (but I hope we won't revert the changes I made).  We
>  > can always change it back later if we discover a need.
> I'm in between: I don't see why this should be only in the prologue,

Ok, I think I misunderstood the intention of the previous behavior in part 
because of the broken error message: it complained that the (one and only) 
%start was actually a second %start just because it appeared after the 
first rule.  Maybe the real bug was just this error message's wording.

> but it should not be after what it refers to.

So, what you really want is to require `%start nterm' to appear before the 
rule whose LHS is nterm?  Or before all rules that contain nterm on the 
LHS or RHS?  That isn't the same as the previous restriction that requires 
it before all rules.

I perhaps could have bought the previous restriction if the justification 
is that it promotes a top-down grammar form: start symbol is first.  (But 
what if someone prefers bottom-up?)  However, I don't follow the 
declaration-before-use argument.  One might argue that `%start nterm' 
*uses* nterm as the start symbol while `nterm: RHS ;' declares/defines 
nterm.  (In fact, that actually sounds right.)  That would mean that 
%start should be last.

> That's the reason why I relaxed the constraint on the prologue
> directives :)  But that's different, it is a matter of *modularity*,
> not of commutativity.

Ok, thanks for clarifying.  I too feel strongly about modularity.  At 
first, I thought you meant commutativity as general order-independence.  
However, it now sounds like you're referring specifically to 

reply via email to

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