Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!news.iecc.com!.POSTED!nerds-end From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.compilers Subject: Re: precedence have both ways Date: Fri, 31 May 2013 10:54:00 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 57 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <13-05-023@comp.compilers> References: <13-05-010@comp.compilers> <13-05-018@comp.compilers> <13-05-020@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1370027780 10339 64.57.183.58 (31 May 2013 19:16:20 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Fri, 31 May 2013 19:16:20 +0000 (UTC) Keywords: parse, theory Posted-Date: 31 May 2013 15:16:20 EDT 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:909 jgk@panix.com (Joe keane) writes: >One person designs a language 'C1' with precedence: > > [higher] > ... > | > & > <, <=, >, <= > ==, != > ... > [lower] > >Some other person designs a language 'C2' with precedence: > > [higher] > ... > <, <=, >, <= > ==, != > | > & > ... > [lower] > >They're the same besides that. > >To compromise, they make a new language 'C3' such that a program is >valid C3 if it is valid C1 and valid C2 -and- both ways mean the same. > >Is there some good way to do this -in the grammar-? Sure, you don't want | & to asssociate with < <= > >= == != (I find the remaining associations questionable, but let's stick with your example). So write the grammar in a way that makes the wanted associations explicit and does not contain the unwanted associations: boolexpr: orexpr | ineqexpr ; orexpr: orexpr '|' andexpr | andexpr ; andexpr: andexpr '&' lower | lower ; ineqexpr: eqexpr ineqop eqexpr | eqexpr ; eqexpr: lower eqop lower | lower ; ... term: '(' highest ')' | ... ; (This assumes that a