[antlr-interest] Modifying token type within parser

Ric Klaren ric.klaren at gmail.com
Wed Jul 13 01:09:30 PDT 2005


On 7/12/05, Jeff Dahl <jddahl at micron.com> wrote:
> Is it possible to modify the token type within the parser?
> 
> I tried:
> 
>     parser_rule:  t:TOKEN {t.setType(OTHER_TOKEN);}
> 
> but, the actual token passed up is still of type TOKEN.

What are you exactly trying to do? Changing the token in the parser
has very little effect. E.g. here the token is recognized as TOKEN
changing the type afterwards will not change the parse outcome.

If you're trying to build a tree with a different token type just use
the AST construction syntax to add the appropriate token to the AST
(might have to turn automatic construction of for the rule).

Cheers,

Ric


More information about the antlr-interest mailing list