[antlr-interest] Dumping out lexer token stream?

Randall R Schulz rschulz at sonic.net
Sat Jun 23 09:37:45 PDT 2007


Hello again,

It turns out this was a false alarm. My execution class-path was all 
messed up, though that in my IDE and in my Ant file was correct.

Sorry for the noise.

For the Java users, the code I used is one example of how to dump the 
token stream.


Randall Schulz


On Saturday 23 June 2007 09:22, Randall R Schulz wrote:
> ...
>
> I wrote this test code (use a fixed-width font, of course):
>
>   CLIFLexer           lexer       = null;
>   PrintStream         out         = System.out;
>
>   try {
>     lexer = new CLIFLexer(new ANTLRFileStream(fileName));
>   }
>
>   catch (IOException exIO) {
>     System.err.printf("CLIF: Cannot open file \"\%s\"\%n", fileName);
>     return;
>   }
>
>
>   out.format("\%nParsing \"\%s\"\%n", fileName);
>
>   TokenStream         tokens      = new CommonTokenStream(lexer);
>   int                 nTokens     = tokens.size();
>
>   for (int iToken = 0; iToken < nTokens; iToken++) {
>     Token             token       = tokens.get(iToken);
>
>     out.format("\%6d: \%4d.\%3d: T\%3d-C\%3d; \"\%s\"\%n",
>                iToken,
>                token.getLine(), token.getCharPositionInLine(),
>                token.getType(), token.getChannel(),
>                token.getText());
>   }



More information about the antlr-interest mailing list