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

Bob Frankel bios.bob.frankel at gmail.com
Tue Nov 10 08:35:05 PST 2009


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()???

thanks....


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


More information about the antlr-interest mailing list