bug-bison
[Top][All Lists]
Advanced

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

Re: $<out of range>


From: Paul Eggert
Subject: Re: $<out of range>
Date: Thu, 25 Apr 2002 11:58:47 -0700 (PDT)

> From: Akim Demaille <address@hidden>
> Date: 25 Apr 2002 17:22:32 +0200
> 
> I suppose the intent is to assign a value to the third symbol, which
> is the mid-rule action, i.e., it is actually $$ which should be used.

Yes, $3 is equivalent to $$ here, since it appears in a semantic action
that is the 3rd component in the rule.

> So, I hope POSIX declares this is an heresy

No, it's allowed.  POSIX says of `$number':

  If number refers to an element past the current point in the rule, or
  beyond the bottom of the stack, the result is undefined.

Here the "current point in the rule" is 3, so $3 is allowed.
Since type checking is enabled, a type is required here, but the
grammar actually says `$<ttype>3' so it satisfies the type-checking
requirement too.

Had the grammar specified $4, it would have been undefined behavior.

If this usage bothers you on style grounds, I suppose it might be
reasonable to issue a diagnostic like this:

parse.y:2120: warning: suggest using $<ttype>$ instead of $<ttype>3

But this brings up the issue of whether Bison should enforce style rules.
Maybe Bison should have an option to suppress warnings?



reply via email to

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