[antlr-interest] custom TokenLabelType and EOF/Error tokens

Jim Idle jimi at temporal-wave.com
Tue Nov 10 08:55:52 PST 2009

Do you have:




? I am thinking that you do have that and that is why you are getting the cast problems right? 




From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bob Frankel
Sent: Tuesday, November 10, 2009 8:35 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] custom TokenLabelType and EOF/Error tokens


following idioms i've seen posted elsewhere, i've created a MyToken class that inherits from CommonToken; my Lexer then overrides Token Lexer.emit(), at which time i create instances of MyToken....

things work fine, until the parser encounters a syntactic error....  from what i can tell, the parser inserts an "error" token of type CommonToken; this then leads to a class cast exception in the surrounding parser rule when attempting to assign a CommonToken value through a generated (MyToken) cast....

i've also noticed a similar problem when my grammar explictly includes the special EOF token; again, the token created here is of type CommonToken, which leads to a class cast exception when later assigned through a (MyToken) cast inside the generated parser class....

is there some other method i should be overriding beyond Token Lexer.emit()???


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091110/5947ec1d/attachment.html 

More information about the antlr-interest mailing list