[antlr-interest] Re: Nondeterminism problem
sarah2geller
sarah2geller at yahoo.com
Sat Dec 13 11:26:31 PST 2003
--- In antlr-interest at yahoogroups.com, "Oliver Zeigermann"
<oliver at z...> wrote:
> --- In antlr-interest at yahoogroups.com, "Weida Ma" <weida_ma at y...>
> wrote:
> > I am getting a nondeterminism warning with a parser:
> >
> > definition
> > : class_decl_or_def | interface_decl_or_def
> > ;
> >
> > class_id
> > : "class" IDENTIFIER
> > ;
> >
> > class_decl_or_def
> > : (local_qualifier)? class_id
> > ;
> >
> > interface_id
> > : "interface" IDENTIFIER
> > ;
> >
> > interface_decl_or_def
> > : (local_qualifier)? interface_id
> > ;
> >
> > local_qualifier
> > : "local"
> > ;
> >
> >
> > SliceB.g:38: warning:nondeterminism between alts 1 and 2 of block
> upon
> > SliceB.g:38: k==1:"local"
> > SliceB.g:38: k==2:IDENTIFIER
> >
> > I think "class" and "interface" should be able to distinguish
> > class_decl_or_def and interface_decl_or_def when k == 2. But it
> seems
> > I am wrong? I'd appreciate any help.
>
> This is the prediction code for rule definition:
>
> if ((LA(1)==LITERAL_class||LA(1)==LITERAL_local) &&
> (LA(2)==LITERAL_class||LA(2)==IDENTIFIER)) {
> class_decl_or_def();
> } else if ((LA(1)==LITERAL_interface||LA(1)==LITERAL_local) &&
> (LA(2)==IDENTIFIER||LA(2)==LITERAL_interface)) {
> interface_decl_or_def();
> }
>
> This actually corresponds to the above warning. It seems to me you
are a victim of approximated LL lookahead :(
>
> Or am I wrong? Experts?
>
> Oliver
Correct. The grammar is strong LL(2), confirmed by the SLK parser-
generator (http://parsers.org).
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list