[antlr-interest] assign a derived token to the lexer
Ric Klaren
klaren at cs.utwente.nl
Tue May 27 02:57:48 PDT 2003
On Tue, May 27, 2003 at 09:22:27AM -0000, thomaskrebs wrote:
> I want to assign a different Token than CommonToken to the lexer. In
> lexer.html at lexer.html#Token_Attributes it is documented how to do
> that. But this seems to be wrong:
>
> ImageToken t = new ImageToken(IMAGE,$getText);
>
> t.setAttributes(attrs);
>
> $setToken(t);
That's the java syntax.
> I assume t should be a pointer to ImageToken and the parameter to
> setToken can not be a Token or a pointer to a Token but a RefToken.
> But I cannot assign a RefCount<ADerivedToken> to the _token inside
> the parser rule. How to deal with that?
Make sure your token is derived of CommonToken, then make a RefToken of
your new token (not a RefCount<ADerived> or you have to cast static_cast
them :( ). When trying to access your own token you would then have to use
the get() method to access the underlying pointer to the refcounter then
dynamic_cast or if the situation permits static_cast (but be sure not to
cheat too much with this pointer).
HTH,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
"Don't call me stupid." "Oh, right. To call you stupid would be an insult
to stupid people. I've known sheep that could outwit you! I've worn
dresses with higher IQs!" --- A Fish Called Wanda
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list