Related articles |
---|
[21 earlier articles] |
Re: Programming language and IDE design jonathan@cobalt.astro.indiana.edu (Jonathan Thornburg) (2013-11-19) |
Re: Programming language and IDE design wclodius@earthlink.net (2013-11-22) |
Re: Programming language and IDE design robin51@dodo.com.au (robin) (2013-11-25) |
Re: Programming language and IDE design martin@gkc.org.uk (Martin Ward) (2013-12-03) |
Re: Programming language and IDE design DrDiettrich1@aol.com (Hans-Peter Diettrich) (2013-12-05) |
Re: Programming language and IDE design hu47121@usenet.kitty.sub.org (2014-03-02) |
Re: Programming language and IDE design gneuner2@comcast.net (George Neuner) (2014-03-02) |
From: | George Neuner <gneuner2@comcast.net> |
Newsgroups: | comp.compilers |
Date: | Sun, 02 Mar 2014 12:21:01 -0500 |
Organization: | A noiseless patient Spider |
References: | 13-11-016 13-11-018 14-03-003 |
Keywords: | parse, C++ |
Posted-Date: | 03 Mar 2014 06:26:15 EST |
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
Return to the
comp.compilers page.
Search the
comp.compilers archives again.