[antlr-interest] antlr beginner confused over ambiguities

Rick Schumeyer rschumeyer at gmail.com
Tue Feb 24 11:52:24 PST 2009


I've read through the ambiguity section of the Definitive Reference, but I'm
still confused on what must be a common problem.  The following grammar is
supposed to recognize a time in the format hh:mm:ss, while also recognizing
arbitrary strings elsewhere.

If the input string is "12:34:45", then of course antlr returns a STRING
token.  I understand why it does that (I think) but I'm not really sure how
to fix that.  I'm fuzzy on the difference between a semantic and syntactic
predicate, and whether one of those is what I need.

grammar STest;

line    :    timestamp;

timestamp
    :    INT ':' INT ':' INT
    ;

INT    :    ('0'..'9')+;

STRING    :    ('!'..'+' | '-'..'~')+; /* anything but ws or comma */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090224/534fe21c/attachment.html 


More information about the antlr-interest mailing list