[antlr-interest] newbie problem with mismatched token in antr v3

Terence Parr parrt at cs.usfca.edu
Tue Oct 16 21:17:02 PDT 2007


On Oct 16, 2007, at 9:09 PM, Norbert Kiesel wrote:

> Hi,
>
> I have problems with "keywords vs. identifiers" in my grammar, and  
> even
> the "grammar CommandLanguage;" from the "Quick  Starter on Parser
> Grammars" does not work for me. The latter gives me a
> "MismatchedTokenException" for "get data from xxx".
>
> My smallest test grammar looks like this:
>
> grammar itf;
> @members { // main method that calls parser.itf() }
> itf	  	: 'interface' itfname EOF ;
> WS		: ( ' '+ ) { $channel = HIDDEN; } ;
> itfname		:  ITFNAME ;
> ITFNAME		: ( 'a'..'z' )+ ' WS ( '0' | '9' | '/' )+ ;
>
> When I run that against "interface xx 9", I get
>
> line 1:10 required (...)+ loop did not match anything at character 'x'
> line 1:14 no viable alternative at character '\n'
> BR.recoverFromMismatchedToken
> line 1:11 mismatched input 'x 9' expecting 'interface'
>
> Can someone please tell me what I'm doing wrong?

Hi Norbert.  Yes, this is a weird thing.  When you call WS, it sets  
the channel to HIDDEN for "current token", which then messes up ITFNAME.

Ter



More information about the antlr-interest mailing list