more on additional conditional operators in C
Tom Pennello
uunet!metaware.com!tom
Sun Aug 12 00:09:36 PDT 1990
> From ucscc!uunet.UU.NET!validgh!validgh.com!dgh Sat Aug 11 11:30:07 1990
> From: ucscc!validgh.com!dgh (David G. Hough on validgh)
>
> I like the idea of
> writing if (x ? y) rather than if (unordered(x,y)) or if ( x !<=> y)
> but whether the ? character could be available for use in conditionals
> considering its other uses in (cond)?: and trigraphs I'll leave to
> the parser constructors to decide.
>
The binary operator "?", as in "x ? y", cannot be introduced in the phrase-
structure grammar for C with the same precedence level as "==" and "!="
without requiring arbitrary look-ahead to resolve an ensuing
reduce-reduce conflict. The problem is that the expression to the
left of ? needs to be reduced to nearly the top of the expression hierarchy
if a : appears down the line somewhere, and needs to be reduced only
to the level of "==" and "!=" otherwise.
To remove this problem we can place the binary "?" at the same precedence level
as ?:. This will probably be unacceptable because of unexpected precedence.
But we also now expose an ambiguity:
a ? b ? c : d can be parsed as
(a ? b) ? c : d
or a ? (b ? c) : d
Thus ? cannot be used as a binary operator.
On the other hand, it is possible to use x ?? y, but this isn't a good
idea since x ??(y+1) would "trigraph" to x [ y+1.
So for ? it's impossible and for ?? there would be problems.
Tom Pennello
Unofficial grammarian of X3J11
More information about the Numeric-interest
mailing list