[antlr-interest] Confused about backtracking

franck102 franck102 at yahoo.com
Sat Nov 26 04:21:09 PST 2011


I think I am missing something fundamental about backtracking. The grammar
below won't parse input such as

a=b.
c=d;

... even though I would expect it to backtrack after realizing that a=b.c
leads to a dead-end. What am I missing?

Thanks!

PS: I am not looking for refactoring options, I have the issue in a complex
grammar that can't easily be refactored.

=====================================
grammar Test;

options {
	output=AST;
	backtrack=true;
}

program
	: statement* EOF
	;
	
statement
	:	ID '=' expr
	|	sep
	;

expr	:	ID suffix;

suffix	:	( '.' expr )*
	;

sep	:	';' | '.';

// LEXER
// ==========================================

ID
	:	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
	;

        
WS  :   ( ' '
        | '\t'
        | '\r'
        | '\n'
        ) {$channel=HIDDEN;}
    ;


--
View this message in context: http://antlr.1301665.n2.nabble.com/Confused-about-backtracking-tp7033712p7033712.html
Sent from the ANTLR mailing list archive at Nabble.com.


More information about the antlr-interest mailing list