[antlr-interest] Heterogeneous token types

C.P.T.de.Gouw at cwi.nl C.P.T.de.Gouw at cwi.nl
Thu Feb 4 09:39:58 PST 2010


>> I think you override emit()
>
> That is indeed what I'm doing, good to hear I'm on the right track :)
>
> But if I refer to a token in a parser action (with $token), it's of type
> CommonToken, and not the subclass of Token that I'm emitting. I can't use
> the TokenLabelType option, since different tokens emit different types of
> token Objects.
>
> Obviously I can cast $token in the parser action to the appropriate type,
> but I hoped this would not be necessary.

To hopefully clarify it a bit further, in bison one can specify with
%union the list of possible types of the token objects, and with %token
<TYPE> x that token x is an object of type TYPE.

Is there some way to do this in antlr (specifying the type of the token
objects on a per-token basis, instead of one single type for all tokens
like TokenLabelType does)?


Stijn


More information about the antlr-interest mailing list