Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: precedence of ?: (was: precedence of && (was: precedence of ?:)) Message-ID: <11082@smoke.BRL.MIL> Date: 16 Sep 89 23:41:14 GMT References: <1265@gmdzi.UUCP> <11030@smoke.BRL.MIL> <11039@smoke.BRL.MIL> <3236@solo10.cs.vu.nl> <11045@smoke.BRL.MIL> <3242@solo12.cs.vu.nl> <11054@smoke.BRL.MIL> <3260@solo5.cs.vu.nl> <11069@smoke.BRL.MIL> <3269@solo5.cs.vu.nl> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article <3269@solo5.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >\ conditional-expression: >\ logical-OR-expression >\ logical-OR-expression ? expression : conditional-expression >\So the interesting question becomes, why is that "expression" for the >\second operand of ?: and not "logical-OR-expression". (I think that >\"conditional-expression" might result in ambiguity.) [...] >I don't think so: a ? b ? c : d : e has only one parse. I had thought perhaps if you got enough interlaced ?: pairs that they might be parsed ambiguously. However (see below), if that were the case then the Standard would have the same problem. After doing some "yacc" experiments with ?: grammars for a while, I found that it's not possible to parse them in the wrong order even under logical-OR-expression ? conditional-expression : conditional-expression However, conditional-expression ? logical-OR-expression : conditional-expression or conditional-expression ? conditional-expression : conditional-expression would lead to an ambiguous grammar. >(If "expression" is OK, "conditional-expression" surely is too!) Yes, "expression" can be expanded to produce "conditional-expression". The more general form in the Standard appears to not introduce ambiguity.