[antlr-interest] lexing expression ('a'..'z')+ not matching single character input

John B. Brodie jbb at acm.org
Wed Dec 13 11:02:10 PST 2006


>Thanks to everyone for the replies.

You are welcome.

>At risk of permanently offending the entire mailing list, i'll include 
>the grammar file in its entirety (since I feel it's far more likely I'm 
>missing something than there is a genuine bug in ANTLR).

No offense taken here, everyone struggles to learn a new tool from
time to time. and I'm certainly no exception to that ;-)

>The input text is a sequence format for carbohydrate structures, some 
>samples follow. "Identifiers" in this grammar are always lower-case, and 
>adhere to the grammar "('a'-'z')+ ('-' ('a'-'z')+)*".
>
>.....examples and grammar snipped.....

You have most of the single lowercase letters specified to be KEYWORDS
of your language.

Take "n", the first error you find, for example. It is a keyword as
specified by the two rules: monosac_type_identifier and
linkage_type_identifier.  and so "n" is NOT an IDENTIFIER.

There should be lots of messages in this mailing list's archives on
how to handle keywords which also may be identifiers...

I suggest you try (re-)generating your parser and lexer and give
antlr.Tool one of the trace enable switches, either -traceLexer or
-traceParser or -trace (i think, my memory of ANTLRv2 switches is
rusty).  and re-run your tests.  you will get copious output showing
what the generated code is attempting to do during the parse.

Hope this helps...
   -jbb


More information about the antlr-interest mailing list