int main(int argc, char** argv) { char* cmdname = *argv++; --argc; if (argc > 1) { cerr << "Usage: " << cmdname << " [filename]" << endl; exit(1); } Scanner* scanner; ifstream* fin = 0; if (argc > 0) { char* fname = *argv++; --argc; fin = new ifstream(fname); string filename(fname); if (!*fin) { cerr << cmdname << ": unable to open " << fname << " for reading" << endl; exit(1); } scanner = new Scanner(*fin, filename); } else { scanner = new Scanner(cin, "stdin"); } AstlTropes::location loc; semantic_type yylval; int token; while ((token = scanner->get_token(yylval, loc)) != 0) { cout << yytname[token - 255]; if (yylval) { cout << " \"" << yylval->get_token().get_text() << '"'; yylval = NodePtr(nullptr); } cout << " at " << make_loc(loc); cout << endl; } delete scanner; if (fin) delete fin; }
inline int yylex(semantic_type* yylval, location* yylloc, Scanner& scanner) { return scanner.get_token(*yylval, *yylloc); }