Related articles |
---|
Re: Is C++ LL(k)? lingu@cs.pku.edu.cn (Lin Gu) (2001-07-23) |
Re: Is C++ LL(k)? kaz@ashi.footprints.net (2001-07-27) |
Re: Is C++ LL(k)? mike@dimmick.demon.co.uk (Mike Dimmick) (2001-07-27) |
Re: Is C++ LL(k)? isaac@latveria.castledoom.org (2001-08-06) |
From: | "Lin Gu" <lingu@cs.pku.edu.cn> |
Newsgroups: | comp.lang.c++,comp.compilers |
Date: | 23 Jul 2001 23:26:05 -0400 |
Organization: | Peking University |
References: | <9jh5uu$olr$1@sunlight.pku.edu.cn> <mSZ67.20253$zb.360918@news1.rdc1.bc.home.com> |
Keywords: | C++, parse |
Posted-Date: | 23 Jul 2001 23:26:05 EDT |
Thanks for the clear elumination.
Your example also reminds me the 'if...if...else' ambiguation. Surely it is
not LR(k).
However, I may have to use an LL(k) compiler generator (Antlr) to
write a compiler for it. Is it difficult? It is expected that I need
to add some rules to disambiguate, but I want to know whether this is
feasible.
Thanks,
lin
"Kaz Kylheku" <kaz@ashi.footprints.net> wrote in message
> In article <9jh5uu$olr$1@sunlight.pku.edu.cn>, Lin Gu wrote:
> >I think C++ is LR(1). But is it LL(k)?
> >
> >I am to write a compiler for a C++ like language and get confused with
this
> >problem.
>
> The C++ grammar is not LR(1) or LL(k), because it contains ambiguities
> that are resolved by dynamically determining the lexical category of an
> identifier, based on the semantics of an earlier declaration. Is X(Y)
> a function call, or a declaration that Y is of type X? Depends on what
> X is, of course.
>
> I believe the C++ grammar can be factored to eliminate left recursion,
> and subsequently can be parsed by a recursive descent parser with
> only one token of lookahead.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.