[antlr-interest] Antlr won't backtrack?

Vitaliy Vitaliy at dbsophic.com
Sun Feb 8 23:11:15 PST 2009


Hi Ter,

Thanks for your quick response!

I'm still confused:

1.       What can I do to suggest Antlr to consider the other alternative, and backtrack instead of failing?

2.       Shouldn't the backtrack option do just that - make Antlr backtrack if it has failed upon a given input?

3.       Why would the variable alternative effect its behavior?

Thanks allot for your help,
Vitaliy

From: Terence Parr [mailto:parrt at cs.usfca.edu]
Sent: Sunday, February 08, 2009 19:46
To: Vitaliy
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Antlr won't backtrack?


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


__________ Information from ESET NOD32 Antivirus, version of virus signature database 3837 (20090208) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090209/49a98b1b/attachment.html 


More information about the antlr-interest mailing list