Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Operator precedence. |
| Date | 2012-05-07 13:29 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <4FA8066F.9010501@verizon.net> (permalink) |
| References | (1 earlier) <4FA79A67.5017@mindspring.com> <jo8d19$bm5$1@dont-email.me> <0.d8eb7be8207401a40630.20120507131802BST.87ipg8famd.fsf@bsb.me.uk> <jo8hg5$71e$1@dont-email.me> <0.c0cec614e11305a0b074.20120507143614BST.877gwof701.fsf@bsb.me.uk> |
On 05/07/2012 09:36 AM, Ben Bacarisse wrote: > James Kuyper <jameskuyper@verizon.net> writes: > >> On 05/07/2012 08:18 AM, Ben Bacarisse wrote: >>> James Kuyper <jameskuyper@verizon.net> writes: >> ... >>>> about the associativity of the operators, how do you parse the two >>>> following expressions: >>>> >>>> a || b ? d , e : f ? g : h >>>> a ? b : c ? d , e : f = g >>>> >>>> Try to determine the correct parsings before reading any farther. The >>>> correct parsings according to the C grammar cannot both be reproduced by >>>> applying a single consistent precedence order to all of the relevant >>>> operators. They are: >>>> >>>> (a || b) ? (d , e) : (f ? g : h) >>>> (a ? b : (c ? (d , e) : f)) = g >>> >>> How do you get this second parse? It's a complex expression but it's >>> only the top level of it that's bugging me. >> >> I should have reviewed the entire discussion before posting that part of >> it. I'd forgotten that you'd already corrected me on that issue the last >> time I discussed it. > > I don't recall that. In fact I seem to recall making a similar mistake > about what the syntax says You did, initially. But you got it right in your message with the following headers: Subject: In how many ways should this fail? Date: Wed, 01 Feb 2012 16:40:09 +0000 ... >> I need to modify the expression to make the point I was trying to make. >> I don't have time to think about it right now, but I'll see what I can >> put together later. I was trying to demonstrate the precise limits of the use of precedence and associativity to describe the C grammar. I provided one example where every operand of the ?: operator had the lowest precedence allowed by the grammar, and one example where what would otherwise qualify as the left and right operands of the ?: operator were expressions with the highest precedence that could not so qualify. However, I forgot to make sure that the second expression had a valid parse. Here's the corrected version of the second expression: a ? b : c ? d , e : f , g and the parse required by the C standard: (a ? b : (c ? (d , e) : f)) , g I was really trying to make several points: 1. The grammar of C expressions that contain no syntax errors or conditional operators can be correctly described using precedence and associativity. 2. Many possible expressions are syntax errors for reasons that cannot be explained using precedence and associativity; they can only be explained by reference to the grammar. 3. Some expressions (mainly involving the middle operand of the ?: operator) are allowed by the C grammar which cannot be explained purely in terms of precedence and associativity. Insofar as item 1 is true, precedence and associativity are redundant with the grammar; because of item 2, the grammar is NOT redundant with precedence and associativity. Those two facts alone are sufficient to justify relying upon the grammar, rather than precedence and associativity. The standard should NOT use both methods of description; every key point in the standard should be expressed exactly once in the normative text. If a requirement is expressed in two different places, the two different expressions might conflict with each other. Item 3 makes it clear that precedence and associativity are not merely redundant with the grammar, but are (in rare circumstances) in conflict with it. I'm not opposed to thinking in terms of precedence and associativity; they're useful concepts for most C operators. It's just important to learn the limits of applicability of those concepts.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Operator precedence. somenath <somenathpal@gmail.com> - 2012-05-06 20:10 -0700
Re: Operator precedence. somenath <somenathpal@gmail.com> - 2012-05-06 20:23 -0700
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-06 23:57 -0400
Re: Operator precedence. Kaz Kylheku <kaz@kylheku.com> - 2012-05-07 03:59 +0000
Re: Operator precedence. pete <pfiland@mindspring.com> - 2012-05-07 05:48 -0400
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-07 07:52 -0400
Re: Operator precedence. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-07 13:18 +0100
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-07 09:08 -0400
Re: Operator precedence. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-07 14:36 +0100
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-07 13:29 -0400
Re: Operator precedence. pete <pfiland@mindspring.com> - 2012-05-07 11:24 -0400
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-07 16:35 +0100
Re: Operator precedence. jgk@panix.com (Joe keane) - 2012-05-10 19:05 +0000
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-10 20:35 +0100
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-11 09:25 -0400
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-11 16:42 +0100
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-11 12:28 -0400
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-11 18:42 +0100
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-11 15:18 -0400
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-11 22:52 +0100
Re: Operator precedence. James Kuyper <jameskuyper@verizon.net> - 2012-05-11 18:39 -0400
Re: Operator precedence. Ike Naar <ike@sverige.freeshell.org> - 2012-05-11 19:20 +0000
Re: Operator precedence. Ike Naar <ike@sverige.freeshell.org> - 2012-05-11 19:28 +0000
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-11 22:28 +0100
Re: Operator precedence. Ike Naar <ike@sverige.freeshell.org> - 2012-05-11 21:45 +0000
Re: Operator precedence. Keith Thompson <kst-u@mib.org> - 2012-05-12 12:11 -0700
Re: Operator precedence. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-11 17:37 +0100
Re: Operator precedence. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-11 16:24 +0100
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-11 20:14 +0100
Re: Operator precedence. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-11 20:56 +0100
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-11 22:21 +0100
Re: Operator precedence. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-12 00:05 +0100
Re: Operator precedence. jgk@panix.com (Joe keane) - 2012-05-11 22:46 +0000
Re: Operator precedence. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-12 00:17 +0100
Re: Operator precedence. jgk@panix.com (Joe keane) - 2012-05-12 19:35 +0000
Re: Operator precedence. "BartC" <bc@freeuk.com> - 2012-05-12 22:39 +0100
Re: Operator precedence. Keith Thompson <kst-u@mib.org> - 2012-05-12 16:07 -0700
Re: Operator precedence. jgk@panix.com (Joe keane) - 2012-05-13 19:08 +0000
Re: Operator precedence. Keith Thompson <kst-u@mib.org> - 2012-05-13 13:17 -0700
Re: Operator precedence. jgk@panix.com (Joe keane) - 2012-05-14 21:06 +0000
Re: Operator precedence. Keith Thompson <kst-u@mib.org> - 2012-05-14 20:42 -0700
Re: Operator precedence. Kaz Kylheku <kaz@kylheku.com> - 2012-05-13 23:20 +0000
Re: Operator precedence. Keith Thompson <kst-u@mib.org> - 2012-05-10 15:24 -0700
csiph-web