Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.misty.com!news.iecc.com!.POSTED!nerds-end From: Ivan Godard Newsgroups: comp.compilers Subject: Re: LL vs LR, was Programming language and IDE design Date: Sat, 01 Mar 2014 20:31:45 -0800 Organization: A noiseless patient Spider Lines: 25 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-03-004@comp.compilers> References: <13-11-016@comp.compilers> <13-11-018@comp.compilers> <14-03-003@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: miucha.iecc.com 1393773093 7870 64.57.183.58 (2 Mar 2014 15:11:33 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sun, 2 Mar 2014 15:11:33 +0000 (UTC) Keywords: parse, comment Posted-Date: 02 Mar 2014 10:11:33 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:1126 On 3/1/2014 4:03 PM, Hannah wrote: > So the C grammar is not LL(k) for any k, either. You can probably parse > that particular part of the C/C++ grammar easily using LR. > > Hannah. The standard way to handle this, and many such other cases where a formal grammar is not LL, is to introduce a function (in recursive descent) or rule (in parser generators) that recognizes "parenthesized thingy" and then figure it out later. Yes, that amounts to LR, but you only need it in a few specialized places. There's an equivalent trick in "DOI=1," in Fortran, where you let the lexer resolve it so the parser sees proper lexemes, not characters. C and its descendants are well known for being inhumane (as well as parser-unfriendly) in their excessive overloading of parens and braces. More friendly (or less keystroke-obsessed) languages require all syntactic regions to have both openers and closers, unique for each kind of region, to avoid the canonical C bug of mismatched closers; Algol68 is an early example of doing it right. [C++ is unusually bad, with some parts just plain ambiguous. In the example a few messages back, I gather that the rule is that if you can parse it as a declaration, it's a declaration, otherwise it's something else. -John]