[antlr-interest] Parser seems to confuse strings and literals

John B. Brodie jbb at acm.org
Mon Aug 14 15:11:40 PDT 2006


on Mon, 14 Aug 2006 17:24:31, Charles Felstead asked:
>Hello,
>

Hi!

>I'm getting a message that says something like: Expecting "aaabbb", Found
>'aaabbb'. The only apparent difference is the single quotes versus double
>quotes.
>
>My parser has a rule that look like this:
>
>root
>      :
>        TOPEN "aaabbb" WORD EQ ATTR_VAL TCLOSE
>        TOPEN "aaabbb" TCLOSE
>      ;
>
>I've based my lexer/parser on the IDLv3 grammar from Gary Duzan. I know the
>problem has to do with the parser trying to match some LITERAL_aaabbb but
>can't figure out a way of making it work. I'm sure this is a basic mistake
>... can someone help me out?

if you are using ANTLR v3, use ' instead of " to surround literals in
the grammar.

if you are using ANTLR v2 and have separate lexer and parser .g files,
token definitions are probably out of sync between the two .g files.
check your usage of the importVocab/exportVocab options and ensure you
are running the Tool on the .g files in the proper order. inspect the
*Token.txt files to ensure that consistent numbering of the tokens has
been used.

if neither of the above, then can't help further. need more info...

Hope this helps
   -jbb


More information about the antlr-interest mailing list