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

Norbert Kiesel nkiesel at tbdnetworks.com
Tue Oct 16 23:21:54 PDT 2007


On Tue, 2007-10-16 at 21:17 -0700, Terence Parr wrote:
> 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.

I tried to drop that { $channel = HIDDEN; }, but still no luck.
Actually, I even get the same error with the following even further
reduced grammar:

itf	  	: 'interface' ' ' itfname EOF ;
itfname		:  ITFNAME ;
ITFNAME		: ( 'a'..'z' )+ ' ' ( '0' | '9' )+ ;

Best,
  Norbert






More information about the antlr-interest mailing list