[antlr-interest] Accessing the token list from a lexer?

O.E. Dragon dragonoe at mcmaster.ca
Thu Jun 1 13:04:25 PDT 2006


On Thu, 1 Jun 2006 15:54:12 -0400
 Richard Tibbetts <tibbetts at streambase.com> wrote:
> In ANTLR 2.7.x is there a clean way to get the token list out of a
> Lexer generated by ANTLR? I'm working in Java if that makes a
> difference.
> 
> I can see hackish ways (access the literals hashtable, and extract
> the
> string byte-by-byte from the ANTLRHashString objects), but nothing
> cleaner is jumping out at me.

You can use use the lexer's "next()" method which is what the generated
parser does. You can then build your own list from that. Of course you
probably won't be able to reuse the same lexer later. There might be a
way to reset the lexer which I don't know. The only way I can think of
is to  re-instantiate it with the same input.

Cheers,
-Olivier


More information about the antlr-interest mailing list