possible operator precedence bug?
Karl Heuer
karl at haddock.ima.isc.com
Sat Oct 15 02:56:07 AEST 1988
In article <4700025 at m.cs.uiuc.edu> kenny at m.cs.uiuc.edu writes:
>karl at haddock.ima.isc.com writes:
>>[someone writes:]
>>>Operator precedence only comes into play when there is ambiguity. Here
>>>there is no ambiguity - the above can only be legal C when parsed one
>>>way, so there is no need to turn to operator precedence.
>>
>>This turns out not to be the case. For example, "a + b=0" ...
>
>Come on, Karl, you can do better than that.
You're right. The point I was trying to make was that the comment was
misleading, as it suggests that the compiler ought to parse "a+b=0" as
"a+(b=0)" because it's the "only way that yields legal C". It doesn't work
that way, of course, but the stereotypical "dumb user" won't know that.
When I wrote that example, I had the dpANS but not K&R in front of me, and I
didn't realize that the latter uses an ambiguous grammar. Using the ANSI
grammar as a base, I think the analogy holds: "a?b,c:d" can only be parsed one
way, so there is no need to parenthesize (b,c). "a+b=0" can only be parsed
one way, which then fails to make sense semantically. "Precedence" is just a
word you can use to help understand the situation; it's not used in the formal
grammar, which is already unambiguous.
Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
More information about the Comp.lang.c
mailing list