[antlr-interest] Geting all tokens from lexer / token stream
Bart Kiers
bkiers at gmail.com
Wed May 11 06:03:17 PDT 2011
CommonTokenStream inherits getTokens() which returns a List of Tokens.
You'll need to cast them to a Token (or something that extends a Token),
since it's a non-generics List list:
CommonTokenStream tokens = new CommonTokenStream(lexer);
for(Object o : tokens.getTokens()) {
Token t = (Token)o;
System.out.println(t);
}
Regards,
Bart.
On Wed, May 11, 2011 at 1:40 PM, Lars von Wedel <lars.vonwedel at gmail.com>wrote:
> Hello,
>
> I am writing an interactive interpreter and I would like to obtain all
> tokens from a lexer of token stream to test, whether the input is complete
> or continued on the next line.
>
> What is the easiest approach to do this ? I tried a CommonTokenStream but I
> am not sure how to tell it to pull all tokens from the lexer.
>
> Thanks and Regards,
> Lars
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
More information about the antlr-interest
mailing list