[antlr-interest] How to recognize a String

The Researcher researcher0x00 at gmail.com
Fri Sep 9 14:46:00 PDT 2011


Hi Gabriel,

It would help if you could post your entire grammar and the exact error
message here.

Also, don't you mean

LPAREN: '(";
RPAREN: ')';

Don't worry we have all been there.

Thanks, Eric




On Fri, Sep 9, 2011 at 5:34 PM, Gabriel Miro <gsmiro at gmail.com> wrote:

> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list