[antlr-interest] Antlr won't backtrack?

Terence Parr parrt at cs.usfca.edu
Sun Feb 8 09:46:27 PST 2009


On Feb 8, 2009, at 2:48 AM, Vitaliy wrote:
> root                        : statements EOF;
> statements            : (statement)+;
> statement             : label
>                                   | keyword
>                                   | variable
>                                   ;
>
> identifier               : Identifier;
> label                       : identifier COLON;
> keyword                : KEYWORD (identifier)?;
> variable                 : identifier;


"keyword label:" will always match rule keyword and then fail.  ANTLR  
will match greedily because you told it to shut up and backtrack.   
It's hiding the warning that identifier can match now or later (during  
statements loop).

Ter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090208/3d00ad04/attachment.html 


More information about the antlr-interest mailing list