[antlr-interest] newbie question

Richard Clark rdclark at gmail.com
Wed Jul 4 22:14:12 PDT 2007


You need to change two things:

1) As Randall noted, lexer rules need to start with an upercase letter.
2) You have a small problem in your character ranges. You're writing
"|..|" which doesn't make sense. "|" means "or" and ".." means "a
range between...". So, try this:

word    :(ALPHANUMERIC |.)* ALPHANUMERIC(ALPHANUMERIC |.)*
            ;

fragment
ALPHANUMERIC
            :UPPERCASE|NATIONAL|LOWERCASE|DECIMALDIGIT
            ;

fragment
DECIMALDIGIT
            :'a'..'z'
            ;

fragment
NATIONAL
            :'#'|'@'|'"'|'$'|'['|']'|'{'|'}'|'^'|'~'
            ;

fragment
LOWERCASE
            :'a'..'z'
            ;
fragment
UPPERCASE
            :'A'..'Z'
            ;

Also, I labeled most of your lexer rules with "fragment" as you
probably want to use them as part of another token, not as a token by
itself.

 ...Richard


More information about the antlr-interest mailing list