[antlr-interest] context information through rule parameters

Gavin Lambert antlr at mirality.co.nz
Thu Jul 3 14:43:49 PDT 2008


At 20:04 3/07/2008, Gerard van de Glind wrote:
 >Because of this, my grammar contains two rules that use
 >backtracking. This also implies that it is impossible to
 >replace these by syntactic predicates.

You're mistaken about that -- all backtracking does is to insert 
automatic syntactic predicates, so anything you can do with 
backtracking you can do by writing your own synpreds.  It might 
just be more work than what you want to do :)

 >	relationalExpression[boolean checkAmbiguity]
 >	  options {backtrack=true;}
 >    		:	formula[true]	(LET^ | GET^ | LT^ | GT^)
 >formula[true]
 >	   	|	dateAtom[true]	(LET^ | GET^ | LT^ | GT^)
 >dateAtom[true]
 >	    	|	booleanAtom[$checkAmbiguity]
 >		;
 >	
 >	formula[boolean bool]
 >		: IDENTIFIER;
 >
 >	dateAtom[boolean bool]
 >		: IDENTIFIER;

Even backtracking isn't going to help you disambiguate those first 
two alts of relationalExpression -- they're exactly identical.



More information about the antlr-interest mailing list