bison-patches
[Top][All Lists]
Advanced

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

Re: too many warnings from Bison CVS for Pike


From: Joel E. Denny
Subject: Re: too many warnings from Bison CVS for Pike
Date: Mon, 6 Feb 2006 12:40:10 -0500 (EST)

On Mon, 6 Feb 2006, Akim Demaille wrote:

> I think the problem should not be addressed in the action part, but
> rather in the rule itself.  I have long been wanting a means to name
> the symbols, instead of numbering them.  Something like
> 
>     exp(res): exp(lhs) '+' exp(rhs) { $res = $lhs + $rhs; }
> 
> We should then look for a syntax that makes explicit what symbols are
> unused, e.g., 
> 
>     exp(): exp(lhs) '+' exp(rhs) { display ($lhs + $rhs); }

Visually, this notation really looks a lot nicer than the ones I 
suggested.  However, I do have one concern about what will happen in 
practice.

Imagine how a bison user would write a new grammar.  After learning the 
new notation, he'd probably start by writing each rule something like:

  exp(): exp() '+' exp()

After writing the grammar, he'd go back and fill in the actions:

  exp(sum): exp(op1) '+' exp() { $sum = $op1; }

But if he forgot his $3, bison would never warn him.  In other words, this 
practice could circumvent the warnings altogether.  We could educate the 
user not to follow this bad practice.  However, when in a hurry, the 
arrogant user (like me) is going to do it anyway because he thinks he 
won't make such stupid mistakes.  Indeed, it might be hard to imagine 
someone making such a stupid mistake for such a simple rule as this 
addition, but it happens.  Moreover, I worry about much more complex 
rules.

OK, perhaps this is a ridiculous concern.  Perhaps no one but me would 
ever adopt such a bad practice, but I fear that many will. Perhaps we 
should let them hang themselves if they do, but I think that's 
unnecessary.

If the unused declaration belongs inside the action, the user would start 
by writing each rule something like:

  exp: exp '+' exp

I doubt seriously that any user would automatically add the following:

  { $<>$; $<>1; $<>3; }

After writing the grammar, he'd go back and fill in the actions:

  exp: exp '+' exp { $$ = $1; }

or, with your new named value notation:

  exp(sum): exp(op1) '+' exp { $sum = $op1; }

And bison would warn him about $3.  `exp()' would be illegal, so he 
wouldn't make the previous mistake.

To me, the declaration that a symbol value is intentionally unused belongs 
where the symbol value would normally be used: in the actions.  In 
general, if that declaration must be placed in the production itself 
instead, it's too tempting to write it by default as you write the 
production.  Yes, we could come up with other variations, such as 
`exp(!)', but I think the same problem might occur.

Joel




reply via email to

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