bison-patches
[Top][All Lists]
Advanced

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

Re: RFC: explicit empty right-hand side of a rule


From: Joel E. Denny
Subject: Re: RFC: explicit empty right-hand side of a rule
Date: Sun, 3 Feb 2013 00:59:12 -0500 (EST)
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)

On Wed, 30 Jan 2013, Akim Demaille wrote:

> > Hi all, (Hi Joel, happy new year!)

Hi Akim.  Happy new year to you too.

> > We have been toying with the introduction of a means to explicitly
> > mark empty right-hand sides of rules.  It's on the explicit-empty
> > branch on gnu.org's repository.  It allows to write
> > 
> >     exp: $empty { … }
> >
> > and it's an exact synonym for
> > 
> >     exp: /* nothing. */ { … }
> > 

Why $empty instead of %empty?  Normally in a Bison grammar file, "$" is a 
prefix for semantic values, and "%" is a prefix for keywords.

> > except that:
> > 
> > - bison does check that there is just $empty and nothing else
> > - it will provide a warning to report implicit empty rhs
> > - the various reports (e.g., foo.output, foo.dot) will use
> >  $empty (or maybe ε where possible) instead of nothing (or
> >  /* empty. */ as is done in some cases).

Makes sense, but I suggest the warning be once per grammar file, by 
default.  Otherwise, it could be pretty noisy for existing grammar files.  
Moreover, maybe Yacc mode should disable it altogether, by default.  
(Sorry, I haven't looked at your branch to see what actually happens.)

> > There is one corner case whose treatment is currently unclear:
> > mid-rule actions.  Currently
> > 
> >     exp: $empty { $$ = foo(); } $empty { $$ = bar(); }
> > 
> > is rejected, because I don't think accepting $empty in this situation
> > actually helping.
> > 
> > /tmp/foo.y:2.6-11: error: $empty must be alone on the right-hand side of 
> > the rule
> > exp: $empty { $$ = foo(); } $empty { $$ = bar(); }
> >      ^^^^^^
> > /tmp/foo.y:2.29-34: error: $empty must be alone on the right-hand side of 
> > the rule
> > exp: $empty { $$ = foo(); } $empty { $$ = bar(); }
> >                             ^^^^^^

I agree $empty is not helpful here.

At the beginning of a rule before a mid-rule action (such as the first 
$empty in the above example), maybe $empty is even harmful.  It's already 
easy to look at a mid-rule action (especially a long one) and mistakenly 
believe you're reading the final action.  That effect is worsened if you 
believe that a preceding $empty means the rule right-hand side is empty.

Adding a $empty after the final action in a rule would probably have a 
strange effect.  That action would apparently become a mid-rule action, 
and the new final action would apparently be the default $$=$1.

The only other place for $empty would be between actions (such as the 
second $empty in the above example), but how often is it useful to have 
two consecutive actions?  Even if two consecutive actions are somehow 
useful, $empty just seems like clutter here.


reply via email to

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