[antlr-interest] literal token names in AntLR3
Loring Craymer
lgcraymer at yahoo.com
Tue Sep 18 13:38:49 PDT 2007
Yes, you can explicitly name tokens in the tokens
section of the grammar:
tokens {
LITERAL_ADD = 'ADD';
}
and then 'ADD' becomes LITERAL_ADD in generated code.
--Loring
--- "Putrycz, Erik" <Erik.Putrycz at nrc-cnrc.gc.ca>
wrote:
> In Antlr 2.x, the literal tokens got friendly field
> names for their type
> number.
>
> E.g. 'ADD' would become LITERAL_ADD but in ANTLR 3,
> all the literals
> become Txxx in the lexer.
>
> When working with trees, it was much easier in the
> past to write
> something like
>
> Switch (node.getType()) {
>
> Case MyTokenTypes.LITERAL_ADD:...
>
> }
>
> Whereas now you need to get back to
> MyParser.tokenNames to find the
> corresponding one.
>
> Is there any way to control the naming of the
> literals and get something
> more friendly than the Txxx?
>
>
>
> Erik Putrycz, Ph.D - Research Associate
>
> Institute for Information Technology - Software
> Engineering Group
>
> National Research Council, Canada - Building M-50,
> 1200 Montreal Road
>
> Ottawa, Ontario, CANADA K1A 0R6
>
>
>
>
____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
More information about the antlr-interest
mailing list