[antlr-interest] short circuiting further evaluation

Jane Eisenstein janee at softweave.com
Fri May 28 05:47:20 PDT 2010


I'm working with a simple expression grammar:

condition:	conditional_expression  EOF
	;

conditional_expression 
	:	conditional_term  
		(  OR conditional_expression  )?
	;

conditional_term 
	:	conditional_factor
		( AND conditional_term  )? 
	;

conditional_factor 
	:	conditional_primary
	|	NOT conditional_primary
	;

conditional_primary 
	: ID 
	| LEFT_PAREN conditional_expression RIGHT_PAREN 
	;

At runtime, ID tokens evaluate to either true or false. Once it is clear the condition as a whole will evaluate to either true or false, I'd like to stop the evaluation and return the value of the condition. So far, all I've managed to do is short-circuit further ID evaluations once an upper level outcome is know.

Is there a way to short circuit the entire parse? I'm not sure how to even tell it would be time to do so.

Jane






More information about the antlr-interest mailing list