[antlr-interest] Re: Nondeterminism problem
mzukowski at yci.com
mzukowski at yci.com
Mon Dec 15 09:27:32 PST 2003
Yes, this is a linear approximation issue. Use a syntactic predicate in
definition to choose between the two options.
definition
: ((local_qualifier)? "class")=>class_decl_or_def
| interface_decl_or_def
;
Monty
-----Original Message-----
From: Oliver Zeigermann [mailto:oliver at zeigermann.de]
Sent: Friday, December 12, 2003 1:11 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: Nondeterminism problem
--- 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
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list