[antlr-interest] Tail ambiguity

Laurie Harper laurie at holoweb.net
Fri May 18 14:36:25 PDT 2007


I'm trying to match a sequence of literal text interspersed with 
expression, where the expression can take either of two forms but can't 
be mixed. For example, 'a ${b} c ${d}' and 'a #{b} c #{d}' are legal, 
but 'a ${b} c #{d}' is not.

The problem is, I get an ambiguity warning I'm not sure how to get rid of...

warning(200): ElSpecParser.g:41:4: Decision can match input such as 
"LiteralExpression EOF" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
w

Here's the relevant rule set:

rValue
	: (rValueComponent1)+ EOF
	| (rValueComponent2)+ EOF
	;

rValueComponent1
	: DOLLAR LCURLY expression RCURLY
	| LiteralExpression
	;

rValueComponent2
	: HASH LCURLY expression RCURLY
	| LiteralExpression
	;

The solution would be easy if mixed expression types were allowed :-/ 
Any suggestions?

L.



More information about the antlr-interest mailing list