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

Austin Hastings Austin_Hastings at Yahoo.com
Wed Oct 17 04:14:05 PDT 2007


Norbert,

Antlrworks gives me the same behavior. You're right - it's strange. I 
had a look at the generated code, and it seemed straightforward until I 
got to the Token code.

If you haven't already done so, set up a test harness and run the java - 
don't rely on antlrworks. See if it produces the same behavior.

=Austin


Norbert Kiesel wrote:
> 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