[antlr-interest] ANTLRWorks question

Mark Wilson mwil at lle.rochester.edu
Tue Oct 13 12:07:58 PDT 2009


Hi Indhu,

I get "Mismatched token exception".  If remove the ESC_SEQ tokens/rules and
make it look as below, it works okay.  If I add the ESC_SEQ (see below)
stuff back in, it will work IF I place an escape sequence as the first
character.  Seems to work okay in the debugger (I'm very new to ANTLR),
though.  I don't see why this wouldn't work in the interpreter, but then
again I don't know much yet.  I have no predicates or anything, just
experimenting with ANTLRWorks wizard generated parser...

Thanks!

STRING
    :    '"' ( ESC_SEQ | ~('\\'|'"') )* '"';

fragment
ESC_SEQ
    :'\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    | OCTAL_ESC
    | UNICODE_ESC


fragment
OCTAL_ESC
    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7')
    ;

fragment
UNICODE_ESC
    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
    ;

On Tue, Oct 13, 2009 at 2:10 PM, Indhu Bharathi <indhu.b at s7software.com>wrote:

>  Prefer using debugger instead of interpreter. Interpreter doesn’t work as
> expected sometimes (when you are using semantic predicates).
>
>
>
> That said, for this particular case it seems to works fine.
>
>
>
> r              :               STRING
>
>                 ;
>
>
>
> STRING
>
>     :  '"' ( ~('\\'|'"') )* '"'
>
>     ;
>
>
>
> Are you using semantic predicates somewhere else that causes the
> interpreter to fail?
>
>
>
> BTW, what is the error message you get?
>
>
>
> Cheers, Indhu
>
>
>
>
>
> *From:* antlr-interest-bounces at antlr.org [mailto:
> antlr-interest-bounces at antlr.org] *On Behalf Of *Mark Wilson
> *Sent:* Tuesday, October 13, 2009 11:34 PM
> *To:* antlr-interest at antlr.org
> *Subject:* [antlr-interest] ANTLRWorks question
>
>
>
> I used the ANTLRWorks wizard to start my grammar.  There appears to be
> something wrong with the STRING token, basically something like "Joe" does
> not parse correctly in the interpreter.  This is what the rule looks like:
>
> STRING
>     :  '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
>     ;
>
> What is this supposed to do?
>
> Thanks,
> Mark Wilson
>
> --
> Mark Wilson
>



-- 
Mark Wilson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091013/f91524c9/attachment.html 


More information about the antlr-interest mailing list