[prev in list] [next in list] [prev in thread] [next in thread] 

List:       antlr-dev
Subject:    Re: [antlr-dev] ANTLR 3.3 and token.EOF_TOKEN
From:       Jim Idle <jimi () temporal-wave ! com>
Date:       2011-01-18 16:57:47
Message-ID: 2af0b5d81a3389716d419a52661a0454 () mail ! gmail ! com
[Download RAW message or body]

You are comparing objectsm which isn't a good idea really anyway. Instead
use getType and check for the Token.EOF type.

while ((token = lexer.nextToken()).getType() !=
org.antlr.runtime.Token.EOF)

Which I think Javac will handle.

Jim

> -----Original Message-----
> From: antlr-dev-bounces@antlr.org [mailto:antlr-dev-bounces@antlr.org]
> On Behalf Of Frank Schilder
> Sent: Tuesday, January 18, 2011 8:04 AM
> To: antlr-dev@antlr.org
> Subject: [antlr-dev] ANTLR 3.3 and token.EOF_TOKEN
>
>
>
> After updating to 3.3, the following while-loop in my code for calling
> a lexer never stops (i.e. The condition never becomes true):
>
> while ((token = lexer.nextToken()) !=
> org.antlr.runtime.Token.EOF_TOKEN)
> {...}
>
>
> In order to fix this problem, I changed my code to get the token before
> I call the while-loop and check for the type directly, which works
> fine, but I would prefer the above code because it's shorter.
>
> I noticed the following line in the release notes:
> - Instead of sharing Token.EOF_TOKEN, I'm now creating EOF tokens so I
> can set the char position for better error messages.
>
> That change seems to be the cause of my problem.
>
> Thanks,
> Frank
>
>
> _______________________________________________
> antlr-dev mailing list
> antlr-dev@antlr.org
> http://www.antlr.org/mailman/listinfo/antlr-dev
_______________________________________________
antlr-dev mailing list
antlr-dev@antlr.org
http://www.antlr.org/mailman/listinfo/antlr-dev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic