[antlr-interest] non-LL(*) HTML grammar

Andrzej borucki_andrzej at wp.pl
Sat Dec 25 09:58:25 PST 2010


I convert grammar http://www.antlr.org/grammar/HTML to ANTLR version 3 
from 2.
I meet error:
error(211): HTML.g:209:3: [fatal] rule paragraph 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.

Rule is:
paragraph
  : OPARA
   (
    /*	Rule body_content may also be just plain text because HTML is
	so loose.  When body puts body_content in a loop, ANTLR
	doesn't know whether you want it to match all the text as part
	of this paragraph (in the case where the </p> is missing) or
	if the body rule should scarf it.  This is analogous to the
	dangling-else clause.  I shut off the warning.
	*/
	/*options {
	generateAmbigWarnings=false;
	}*/
	text
   )*
   (CPARA)?	
   ;

options {backtrack=true;} nothing do, and backtracking is not good 
because slown down parsing. Can be more text:
OPARA text text text .. (CPARA)
OPARA
	:	'<p' (WS ATTR)? '>'
	;

CPARA
	: 	'</p>'		//it's optional
	;

It is possible to left-factoring ? How use syntactic predicates ?


More information about the antlr-interest mailing list