[antlr-interest] Re: Token Stream.

micheal_jor <open.zone at virgin.net> open.zone at virgin.net
Thu Jan 30 00:45:15 PST 2003


--- In antlr-interest at yahoogroups.com, "queengiraffe 
<cow_jumped_moon at h...>" <cow_jumped_moon at h...> wrote:
> Sorry a help call from an absolute novice to compiler design. I'm 
> using Cpp. 
> 
> I understand that to pass the information into the lexer you use:
> 
> CalcLexer lexer(cin);
> 
> But I cannot figure out how you can dump the tokens onto screen by 
> using the lexer class. I wish to do this for testing purpose, so I 
> know what tokens are being generated by the lexer.

Use a loop similar to:

for(;;)
{
    RefToken tok = lexer.nextToken();

    if ( tok->getType() == Token::EOF_TYPE )
        break;

    cout << "Token: " << tok->toString() << endl;
}

You should really wrap this in a try...catch. Also see the some of 
the projects in the examples/cpp directory.

Micheal




 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list