It is probably that the interpreter cannot deal with it to be honest. Use
the debugger rather than the interpreter.

Jim

> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Tom Fiddaman
> Sent: Friday, February 18, 2011 5:13 PM
> To: [email protected]
> Subject: [antlr-interest] baffling grammar behavior
>
> I've built a grammar for much of a declarative simulation language.
> Everything works, except this bit that I've distilled as much as
> possible:
>
> grammar test;
>
> input         :       VARNAME IS LITERAL
>       ;
>
> VARNAME :     VCHAR (SP? VCHAR)*
>     ;
>
> fragment
> VCHAR         : ('a'..'z'|'A'..'Z')
>       ;
>
> fragment
> SP    :       (' ')
>       ;
>
> IS    :       ':IS:'
>       ;
>
> LITERAL:  '\'' ( options {greedy=false;} : . )* '\''
>     ;
>
> WS  :   ( ' '
>       | '\t'
>         | '\n'
>         | '\r'
>         ) {$channel=HIDDEN;}
>     ;
>
> When I feed the interpreter a typical string in ANTLRworks, like y :IS:
> 'frank'
> the first token matched (a VARNAME) is
> y :IS
> followed by a MismatchedTokenException for the rest.
>
> The initial match doesn't make sense to me, because : isn't a possible
> character of my VARNAME. I'm expecting my rules to first pick up the y
> as a VARNAME, then consume the space as WS on the hidden channel, then
> grab the
> :IS: operator.
>
> This works fine if I eliminate the space before the :IS: in the input,
> or simplify the VARNAME to just VARNAME : VCHAR ; or VARNAME : VCHAR
> (VCHAR)* ; but unfortunately the target language permits spaces in
> variable names, so I need the optional space SP?.
>
> I'm hoping that I'm just making a dumb noob syntax error, but any
> suggestions would be much appreciated.
>
> Tom
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to