[antlr-interest] Beginner question: rule preference?
micke.hovmoller at gmail.com
Sat Feb 9 13:49:55 PST 2008
I'm trying to parse this small text:
** Dealing down cards **
Dealt to Player [ Td , 3c ]
With this grammar in ANTLRWorks 1.1.7
: '** Dealing down cards **' NEWLINE 'Dealt to ' ID ' [ ' card ','
card ']' NEWLINE;
card : RANK SUIT;
RANK : ('2'..'9'|'T'|'J'|'Q'|'K'|'A') ;
SUIT : ('d'|'c'|'h'|'s');
ID : ('a'..'z'|'A'..'Z'|'_'|'0'..'9')+ ;
NEWLINE:'\r'? '\n' ;
This gives a MismatchedTokenException when I get to the "Td" input. I
suppose this is because that matches with ID as well. What do I do to
tell the grammar to use the card part only here?
(I have ordered the ANTLR book from Amazon, but it hasn't arrived yet,
and I can't wait to get my project started.)
More information about the antlr-interest