Path: csiph.com!usenet.pasdenom.info!news.lightlink.com!news.iecc.com!.POSTED!nerds-end From: jgk@panix.com (Joe keane) Newsgroups: comp.compilers Subject: Re: Grammar with low-precedence postfix operator? Date: Tue, 10 Feb 2015 21:03:24 +0000 (UTC) Organization: Public Access Networks Corp. Lines: 48 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <15-02-024@comp.compilers> References: <15-02-006@comp.compilers> <15-02-014@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1423619250 34428 2001:470:1f07:1126:0:676f:7373:6970 (11 Feb 2015 01:47:30 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Wed, 11 Feb 2015 01:47:30 +0000 (UTC) Keywords: parse, design Posted-Date: 10 Feb 2015 20:47:30 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1526 Anton Ertl wrote: >For your example involving ^ and ++, I think that one should use >parentheses explicitly in most cases, e.g. (a^b)++^c or a^(b++)^c. >You can leave away the parentheses if there is no ambiguity, as in >your 2++^3, but that's not straightforward to express in BNF. gcc does something like this You can say: if (x & y == 0) probable error, warn or reject if ((x & y) == 0) OK if (x & (y == 0)) OK, if that's what you want I don't know how it is implemented. if (x == 1 && y == 2) fine IMHO if ((x == 1) && (y == 2)) too many parens if (((x >= 1) && (x <= 2)) || ((y >= 1) && (y <= 2))) way too many parens IMHO, but shouldn't reject The reason you don't want to reject these is that, besides that it's style, they could come from macros. If you color parens in macros, you could also look out for macros: #define SUM(X, Y) (X)+(Y) probable error #define DOUBLE(X) (2*X) probable error