Posted By:
Fernando_Colombo
Posted On:
Friday, February 18, 2005 08:15 AM
The following grammar (k=2) -- code: statement; statement: ID "(" ")" | (ID ":")? "while" "(" ")" statement; generates a nondeterminism warning: nondeterminism between alts 1 and 2 of block upon k==1:ID k==2:"(" and is generating the following Java code: if ((LA(1)==ID) && (LA(2)==5)) { match(ID); match(5); match(6); } // Strange generation decision: else if ( (LA(1)==ID||LA(1)==LITERAL_while) && (LA(2)==5||LA(2)==7)) { ... I think ANTLR should not think it's a nondeterminism and should gen
More>>
The following grammar (k=2) --
code: statement;
statement: ID "(" ")" | (ID ":")? "while" "(" ")" statement;
generates a nondeterminism warning:
nondeterminism between alts 1 and 2 of block upon
k==1:ID
k==2:"("
and is generating the following Java code:
if ((LA(1)==ID) && (LA(2)==5)) {
match(ID);
match(5);
match(6);
}
// Strange generation decision:
else if (
(LA(1)==ID||LA(1)==LITERAL_while) &&
(LA(2)==5||LA(2)==7)) {
...
I think ANTLR should not think it's a nondeterminism and should generate Java lines under comment this way:
else if (
(LA(1)==ID&&LA(2)==5)) {
... // match ID ":"
} else if (
(LA(1)==LITERAL_while&&LA(2)==7)) {
... // match "while" "("
}
So, questions are:
1. What is the good reason for ANTLR works this way?
2. How can I remove warning without increasing k?
Thanks!
<<Less