[antlr-interest] How to recognize a String

Gabriel Miro gsmiro at gmail.com
Fri Sep 9 14:34:38 PDT 2011


Hello all!
I'm new to ANTLR and I'm trying to build a simple grammar that can recognize
strings like ('val'). I'm using ANTLRWORKS and it generates a rule for
string values with single quotes and I mapped the parenthesis to lexer
tokens:

RPAREN:'(';
LPAREN:')';
...
STRING
    :  '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\''
    ;


Now, if I try to write the following:

rule : RPAREN STRING

and evaluate the input ('blah', I get an error in the interpreter. I have no
idea why, but I'm thinking the STRING rule is evaluating EOF and returning
an error.

Any ideas on how to make this work?

Regards,
Gabriel Miró
ANTLR Newbie


More information about the antlr-interest mailing list