[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: too many warnings from Bison CVS for Pike
From: |
Hans Aberg |
Subject: |
Re: too many warnings from Bison CVS for Pike |
Date: |
Sun, 29 Jan 2006 14:30:08 +0100 |
On 27 Jan 2006, at 23:59, Paul Eggert wrote:
I checked the Posix spec for Yacc, and it's not entirely clear in this
area and it could be interpreted the way that Pike requires.
<http://www.opengroup.org/onlinepubs/009695399/utilities/yacc.html>
says "By default, the value of a rule shall be the value of the first
element in it." It also says, "The value of the action can be set by
assigning it to $$." One could easily interpret this to mean that the
equivalent of "$$ = $1" must be executed before each action.
I think it is a poor formulation of:
The value of the default action of a rule shall be $$ = $1.
The thing is that throwing in an extra $$ = $1 before any other
actions is harmless under C, but it does not work under C++, which
may have a user defined "operator=()" in which two assignments are
not the same as one. To make things worse, the C++ standard library
has one, std::auto_ptr, of which assignment transfers a pointer from
the RHS to the LHS of the assignment. And it is natural to use such a
class together with Bison actions, in order to avoid unnecessary
copying. When used with the extra default action $$ = $1, the pointer
is simply lost! - I ended up with this problem, and therefore
switched using a reference count instead. I also changed my skeleton
file. (The situation may become even more complicated when using
Bison types under C++, because then the default action may involve
dynamic_cast or static_cast. Then, one cannot use $$ = $1 at all.
Under C, this is not a problem, as one is merely using a union, and $
$ = $1 will copy over the whole union field. There is no support for
such C++ usage yet in Bison, though.)
I suppose we could ask for a clarification from the Open Group,
I think this point need clarification. For C is does not matter
perhaps, but for C++ it should be:
The default action is executed only if no explicit action is given.
If the rule is of length >= 1, the default action is $$ = $1.
If the rule is of length 0, the default action is $$(), that is, $
$ is initialized to its default
constructor value.
but
regardless of what they say, I suspect that many grammars rely on this
assumption and we should think twice before generating warnings about
it.
This way of behaving, with the $$ = $1 always executed seems to have
existed up to the point I discovered the C++ problem. So probably,
many C programs rely on it. The problem is that it does not harm
under C (except for some time), but indeed may harm under C++, and it
may be confusing to have radically different behavior under C/C++.
And it seems strange that a default action should be executed when an
explicit action has been given. But on the other hand, one does not
want to break existing programs.
In the long run I think Bison needs different flavors of warning
options, for users who want to be more or less picky.
My guess is that perhaps some option is needed. It is perhaps though
difficult to motivate to C users to not have $$ = $1 always executed,
if it does not cause any harm in doing it.
Hans Aberg
- too many warnings from Bison CVS for Pike, Paul Eggert, 2006/01/28
- Re: too many warnings from Bison CVS for Pike,
Hans Aberg <=
- Re: too many warnings from Bison CVS for Pike, Joel E. Denny, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Hans Aberg, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Joel E. Denny, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Hans Aberg, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Joel E. Denny, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Hans Aberg, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Joel E. Denny, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Hans Aberg, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Joel E. Denny, 2006/01/29
- Re: too many warnings from Bison CVS for Pike, Hans Aberg, 2006/01/30