Path: utzoo!attcan!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 ?:) Message-ID: <11054@smoke.BRL.MIL> Date: 13 Sep 89 18:38:19 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> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 34 In article <3242@solo12.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >gwyn@smoke.BRL.MIL (Doug Gwyn) writes: >\... there is no legal way to parse >\ 0 && i = 0 >\as >\ (0 && i) = 0 >\but there is a legal parse as >\ 0 && (i = 0) Actually, now that I've gotten back to my desk where I keep a copy of the proposed Standard, I find that you must supply the parentheses to get a legal parse. Without them there is no derivation from the grammar production rules. (I think. I keep getting this wrong.) >gcc (ANSI or what?) does accept > 0 ? 0 : i = 0 >but it does NOT accept > 0 && i = 0 >In fact, I've never used a C compiler that accepted the latter construct. >Of course I fully agree it should be accepted. Maybe the intention is to avoid confusion. For example, i = 0 && i = 0 would either have to have an ambiguous parse, or else its interesting subexpression would be parsed differently depending on context, which is confusing. I seem to recall Dave Prosser telling me that the Standard's grammar for C (apart from the preprocessor) constituted a "phrase structure" grammar. Perhaps if I knew what that meant I'd understand the rationale behind these particular expression parsing rules. It does appear that the current rules avoid parsing ambiguity. That's probably a worthwhile constraint.