Path: utzoo!utgpu!water!watmath!clyde!rutgers!rochester!ur-tut!sunybcs!boulder!hao!noao!mcdsun!sunburn!gtx!al From: al@gtx.com (0732) Newsgroups: comp.lang.c Subject: Re: C sintax Message-ID: <548@gtx.com> Date: 28 Jan 88 16:40:31 GMT References: <7072@brl-smoke.ARPA> <7160@brl-smoke.ARPA> <3932@hoptoad.uucp> <4079@june.cs.washington.edu> <4080@june.cs.washington.edu> Reply-To: al@gtx.UUCP (Al Filipski) Organization: GTX Corporation, Phoenix Lines: 41 In article <4080@june.cs.washington.edu> pardo@uw-june.UUCP (David Keppel) writes: ->>What, precisely, does x+=*a+++*b mean? -> ->Well, actually it is ambiguous. There are 2 (or more?) ways to parse ->it. I'm not sure the behavior is defined from lexer to lexer as to ->which one is preferred. Here are some possible interpretations: -> -> tmp = *a + ++*b; /* means increment *b and add that to *a */ -> x += tmp; -> switch (x) {...} -> ->the (an) other is -> -> tmp = *a++ + *b; /* means add *a to *b and increment a */ -> x += tmp; -> switch (x) {...} -> ->Not, of course that this is the most obfuscated code possible, but ->it does get the point across. Actually, it is not ambiguous. RTFK&R. The issue is whether x+++y means (x++)+y or x+(++y). According to K&R, p 179, the answer can only be (x++)+y. The rule is "the next token is taken to include the longest string of characters which could possibly constitute a token." I think there is an implicit assumption of left-to-right parsing. Notice that this makes 1+++b syntactically illegal, even though it might reasonably be interpreted as 1+(++b). I'll stick my neck out and say I don't think there ARE any syntactic ambiguities in C. (there are, of course, the semantic ones resulting from undefined order of evaluation). The potential ambiguities such as the dangling else and those involving the comma operator are solved by fiat. Are there any syntactic ambiguities K&R didn't resolve? ---------------------------------------------------------------------- | Alan Filipski, GTX Corp, 2501 W. Dunlap, Phoenix, Arizona 85021, USA | | {ihnp4,cbosgd,decvax,hplabs,amdahl}!sun!sunburn!gtx!al (602)870-1696 | ----------------------------------------------------------------------