bug-bison
[Top][All Lists]
Advanced

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

Re: Default rule


From: Paul Eggert
Subject: Re: Default rule
Date: Fri, 18 Oct 2002 17:54:16 -0700 (PDT)

> From: Hans Aberg <address@hidden>
> Date: Wed, 16 Oct 2002 13:45:06 +0200
> 
> The reason for omitting "if (yylen > 0)" was surely once upon the
> time to save some parsing time,

No, the reason is just as the comment says: to suppress an
otherwise-annoying GCC warning about use of an uninitialized variable.
In the old days, there was an "if (yylen > 0)" test, but after GCC
started issuing that warning, the test was removed.

> the current implementation invites sloppy programming: One can drop
> some $$.field = $1.field assignments in the grammar, even when the
> rule is not default....

True.  Perhaps it would be better to move the yyval assignment into
the default case of the yyn switch.  That would cause the GCC warning
to be generated for the sloppy grammars that you mention.

> -- I think it would be safer to do nothing in the case of rule length zero
> than producing some ad hoc garbage.

But doing nothing also produces ad hoc garbage.

> -- When using %union, YYSVALDEFAULT would need an extra argument:
> #ifndef
> #define YYSVALDEFAULT(yyval, type) /* yyval.type = ... */
> #endif

This issue arises only for untyped grammars, since an error message is
generated for typed grammars if the default action has the wrong type
(which is the case here).  I don't think it's worth making it
configurable for the untyped-grammar case, as those grammars tend to
be pretty simple and don't need configuration.

Perhaps it's simpler just to zero out yyval here.




reply via email to

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