antlr guessing mode (bug?)
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alon_Tamir
Posted On:   Saturday, February 5, 2005 11:12 PM

I have a problem that during parsing I get NullPointerException on my code. It seems to be caused from something in guessing mode of the antlr. My grammer is pretty complex, but I'll show here a simple example of the problem. I have the following rules: rule_a: { MyObject o1 = null; } rule_b ( { o1 = new MyObject(); } rule_c[o1] )? ; rule_c[MyObject o1] { o1.addData("in rule_c"); } : "xxx" ; So - when entering rule_c, o1 must not be null. However the code generated has a guessing dependecy that cause the o1 to be   More>>

I have a problem that during parsing I get NullPointerException on my code. It seems to be caused from something in guessing mode of the antlr. My grammer is pretty complex, but I'll show here a simple example of the problem.



I have the following rules:


			
rule_a:
{
MyObject o1 = null;
}
rule_b
(
{
o1 = new MyObject();
}
rule_c[o1]
)?
;


rule_c[MyObject o1]
{
o1.addData("in rule_c");
}
:
"xxx"
;



So - when entering rule_c, o1 must not be null.
However the code generated has a guessing dependecy that cause the o1 to be null:


			
if ( inputState.guessing==0 ) {
o1 = new MyObject();
}



What is this guessing mode? Is it a bug on antlr, or problem on my grammer?    <<Less

Re[2]: antlr guessing mode (bug?)

Posted By:   Alon_Tamir  
Posted On:   Tuesday, February 8, 2005 05:42 AM

Then - You are saying that having


(rule_a) => rule_a rule_b



might cause a bug in antlr that will cause to run code segments in grammer that should not be invoked?

Re: antlr guessing mode (bug?)

Posted By:   valentin_tihomirov  
Posted On:   Monday, February 7, 2005 01:36 PM

The semantic rules are not evaluated during synthactic prediction. It seems you have a
(rule_a) => rule_a rule_b
somewhere in your grammar. The parsing is not purely deterministic, the syntactic prediction implies possibility of basctracking; thus, the semantic actions must be forbidden. This feature failed one of my attempts to enable keywords as identifiers.
About | Sitemap | Contact