Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.linkpendium.com!news.linkpendium.com!news.iecc.com!.POSTED!nerds-end From: George Neuner Newsgroups: comp.compilers Subject: Re: Programming language and IDE design Date: Sun, 02 Mar 2014 12:21:01 -0500 Organization: A noiseless patient Spider Lines: 44 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-03-005@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=us-ascii Content-Transfer-Encoding: 7bit X-Trace: miucha.iecc.com 1393845975 99029 64.57.183.58 (3 Mar 2014 11:26:15 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Mon, 3 Mar 2014 11:26:15 +0000 (UTC) Keywords: parse, C++ Posted-Date: 03 Mar 2014 06:26:15 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:1127 On Sun, 2 Mar 2014 00:03:18 +0000 (UTC), hu47121@usenet.kitty.sub.org (Hannah) wrote: >I don't think C++ is LL(2). > >Think e.g. > > T(a)++; >vs. > T(a)[5]; > >(Example from n3485, page 131). > >The former is a statement, while the latter is a declaration, and you >can decide this only very late. As the first four tokens are the same, >C++ can't be LL(4), at least. > >As you can substitute '('^n x ')' ^n for a in this example (i.e. enclose >that identifier in any number of parentheses), C++ isn't LL(n) for any n. >(In the first case, "a" is a subexpression, that can be parenthesized, >while in the second case, it's the declarator-id that can also be >parenthesized). I suppose that it depends on your definitions: a "syntax" token is different from a "grammar" token ... a single grammar token can represent an expression of any complexity. I think the whole notion of lookahead is ambiguously level dependent. But I concede your point re: syntax. >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. However, both C and C++ are LL(*). LL(*) Antlr-3 grammars are available for both http://www.antlr3.org/grammar/list.html Also in that list you'll find an LL(k) Antlr-2 grammar for C/C++ which at quick glance claims to be LL(2) ... but I haven't examined it to know what tricks it may be employing. http://hg.netbeans.org/main/file/tip/cnd.modelimpl/src/org/netbeans/modules/c nd/modelimpl/parser/cppparser.g George