[antlr-interest] assigning preference to one of two intersecting rules

cgorski at cgorski.org cgorski at cgorski.org
Fri Aug 17 10:17:31 PDT 2007


In the grammar that follows, I am attempting to match all 
strings such as:

"54"
"a54"
"#75"
"n.ob89"

I'd like to be able to extract the Prefix and Number 
values for later use in a parser.  What's the best way to 
go about this?  How do I tell
ANTLR to attempt to match first the first rule in 
BoxNumberComplete?


BoxNumberComplete : BoxNumberPrefix BoxNumber
                   | BoxNumber
                   ;

fragment
BoxNumberPrefix : 'number'
                 | 'n''.'*'o''.'*
                 | '#'
                 ;
fragment
BoxNumber : (Alpha|Digit)+;

fragment
Alpha : 'a'..'z';

fragment
Digit : '0'..'9';

Thanks,
Chris




More information about the antlr-interest mailing list