[antlr-interest] Resolving a non-LL(*)

Eric Astor eastor1 at swarthmore.edu
Mon Jan 8 08:28:56 PST 2007


Hey everyone,

So, I'm new to ANTLR and to formal grammars - and I have this little
error in a critical grammar I'm writing that I just can't resolve. I'm
using 3.0b5, and the ANTLRWorks jar from the website:

[11:05:03] error(211): IndentTest.g:6:4: [fatal] rule macro_call has
non-LL(*) decision due to recursive rule invocations reachable from alts
1,2.  Resolve by left-factoring or using syntactic predicates or using
backtrack=true option.

I've reduced the grammar that induces the error to give a basic example,
and what I've come up with is below. Can anyone suggest a way around
this? I've found that eliminating the recursive alternate in
arbitrary_text does the trick, but I still need a way to match all text
to the end of an indentation block.

Any ideas?

Thanks very much,
Eric Astor

--- Example grammar follows ---

grammar IndentTest;

macro_call
	:	':' WORD NEWLINE
		INDENT
			( (WORD ':') => parameter_block NEWLINE arbitrary_text
			| arbitrary_text
			)
		DEDENT
	;

parameter_block
	:	(WORD ':' (~(NEWLINE))* NEWLINE)+
	;


arbitrary_text // Consume to the end of the current indentation block
	:	( ~(INDENT|DEDENT)
		| (INDENT arbitrary_text DEDENT)
		)+
	;


More information about the antlr-interest mailing list