Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: precedence of && (was: precedence of ?:) Message-ID: <11064@smoke.BRL.MIL> Date: 14 Sep 89 12:23:03 GMT References: <8034@goofy.megatest.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 34 In article <8034@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: >But let's be generous and give him partial credit, assuming that >the grammar is the Law and the precedence table is for amusement >purposes only. Don't give me any credit, because it turned out that there was no legal parse for the expression at all. The grammar IS the Law. I don't know exactly WHAT the precedence table is for, but it may be intended as a convenient quick way to check whether one needs to use grouping parentheses when writing code, without having to painstakingly work through the production rules. >I would like to hear the rationale behind creating such a convoluted >grammar, when the precedence rules are so much easier to understand. Having recently made several mistakes with this, I'm perhaps not the best source for that rationale. Note, however, that the grammar allowed me to eventually figure out the correct answer, whereas the precedence rules initially led me to jump to a false conclusion. (I made an error in applying the grammar, too, but that could be manually verified and corrected. It wasn't the fault of the grammar.) I don't find the grammar especially "convoluted"; in fact it's relatively straightforward. The reason for the several types of expression is precisely to reflect the correct precedence without requiring precedence to be provided by means outside the grammar. >Besides, the precedence rules are also much better for compiler- >writers, too! I disagree with this. In implementing several language translators, I've always used the formal grammar production rules directly in the implementation. I've never had occasion to try to impose precedence rules any other way.