I am writing the front end of a compiler for a project, and I'm trying to figure out what is the best method tokenize source code. I can not choose between two ways:
1) the tokenizer reads all the markers:
bool Parser::ReadAllTokens() { Token token; while( m_Lexer->ReadToken( &token ) ) { m_Tokens->push_back( token ); token.Reset();
and then the parsing phase begins, working on the m_ Tokens list. Thus, the getNextToken (), peekNextToken (), and ungetToken () methods are relatively easy to implement by an iterator, and the parsing code is well written and understandable (getNextToken () is not broken ie:
getNextToken(); useToken(); getNextToken(); peekNextToken(); if( peeked is something ) ungetToken(); .. ..
)
2) the parsing phase begins and, if necessary, a token is created and used (the code seems not so clear)
What is the best method and why? and efficiency? in advance for replies
Salv0 source share