// lexer_driver.cpp // ~~~~~~~~~~~~~~~~ // author: Hung Q. Ngo // - a simple driver for the the Lexer class #include #include "Lexer.h" using namespace std; // print all tokens of a given lexer obj void print_tokens(Lexer lexer) { Token tok; while (lexer.has_more_token()) { tok = lexer.next_token(); switch (tok.type) { case IDENT: cout << "Identifier: " << tok.value << endl; break; case STRING: cout << "String: " << tok.value << endl; break; case ENDTOK: cout << "END of string token -- should not reach here\n"; break; case ERRTOK: cout << "ERROR Token" << endl; return; } } } // a few tests int main() { Lexer lexer("This \"is a good\" \t test"); print_tokens(lexer); lexer.set_input("This \"is a \" test and \"an error"); print_tokens(lexer); return 0; }