dcsimg
Strange nondeterministic expressions
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gyula_Szentirmay
Posted On:   Thursday, July 22, 2004 02:18 AM

I've found two expressions which are nondeterministic in antlr's opinion. I failed to understand why they are nondeterministic, moreover I think the second expression results wrong code. Did I do something wrong? Is it a bug?

			
class RTPParser extends Parser;
options{
k=2;
}
bug1: A (B A)* (B)? C (A)*;
bug2: (A B|B C)|A C;

class RTPLexer extends Lexer;
options {
k=1;
}
A: 'a' ;
B: 'b' ;
C: 'c' ;

Re: Strange nondeterministic expressions

Posted By:   Carles_Biosca  
Posted On:   Friday, August 13, 2004 05:05 AM

Maybe it is cause it can obtain A C from both rules, so when he reads A C it cannot decide which rule has to be applied.

In the first rule, A, 0 ocurrences of (B A), 0 ocurrences of (B), C and 0 ocurrences of (A) and we have A C.

bug1: A (B A)* (B)? C (A)*;

In this case it is obtained directly.
bug2: (A B|B C)|A C;

Re: Strange nondeterministic expressions

Posted By:   Gyula_Szentirmay  
Posted On:   Thursday, July 22, 2004 02:26 AM

I'm so stupid. Now I understand that the first expression requires k=3. Sorry for posting stupid questions. But I still don't understand why the second is wrong.
About | Sitemap | Contact