[antlr-interest] Confused about backtracking

Christian chwchw at gmx.de
Mon Nov 28 05:57:51 PST 2011


Hi,

what is the error/exception message?

Regards,
Christian

Am 26.11.2011 13:21, schrieb franck102:
> 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.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>



More information about the antlr-interest mailing list