[antlr-interest] Backtrack option breaks AST rewrite

Thomas Brandon tbrandonau at gmail.com
Fri Jul 21 22:21:44 PDT 2006


In Antlr 3.0b3 setting the backtrack option seems to break parsing of
tree rewrites using closures. This grammar:
grammar CParser;
options {
    backtrack=true;
    output=AST;
}
tokens { TU; }
translation_unit
	: external_declaration+
	  -> ^( TU external_declaration+ /*Err here*/)
	;
external_declaration
	: 'a'
	;

gives errors:
0:0: syntax error: codegen: <AST>:0:0: unexpected AST node: synpred3
13:13: expecting EOB, found 'external_declaration'
(13,13 is at the end of the tree rewrite block, as indeicated)
Removing the backtrack option fixes it, as does removing the closure
on the rewrite rule (i.e. "-> ^( TU external_declaration)").

Thanks,
Tom.


More information about the antlr-interest mailing list