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 14:13:28 -0700 (PDT)

> From: Akim Demaille <address@hidden>
> Date: 25 Apr 2002 21:59:30 +0200

> Paul> Yes, $3 is equivalent to $$ here, since it appears in a semantic
> Paul> action that is the 3rd component in the rule.
> 
> How can it be?  I mean, there is a reduction here, so by definition,
> $$ will overwrite $3.

Sorry, I had thought that $$ and $3 would be different names for the
same variable, so there's wouldn't be a conflict.  But I was mistaken.

> Actually, I was so disturbed that this could work, that I wrote a
> test case, and, unless I'm missing something, even if POSIX says so,
> Bison doesn't, and G++ is broken somewhere.

On further thought I agree with you.  Both byacc and Solaris yacc
reject your test case.  So even if POSIX requires the behavior (which
now seems to be quite debatable), its use is not portable in practice.

> POSIX lost its mind.  There is a rule reduction here, so Bison pops
> the stack and pushes $$.  What was written in $3 is popped even more.
> Either I'm missing something obvious, or really, POSIX asks us to
> rewrite the mid-rule actions to use $$.

On rereading the standard, I found another sentence that I had
missed the first time:

  Actions can occur anywhere in a rule (not just at the end); an
  action can access values returned by actions to its left, and in
  turn the value it returns can be accessed by actions to its right.

This sentence implies that this mid-rule action cannot access $3,
since the action cannot be to the left of itself.  So Bison is correct
to reject the C++ grammar.

Sorry about the confusion.



reply via email to

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