void Action::visit(Visitor& visitor) const { switch (m_command) { case Clear: visitor.clear(); break; case Insert: visitor.insert(m_level, m_key1); break; case Replace: visitor.replace(m_level, m_key1, m_key2); break; case Remove: visitor.remove(m_level, m_key1, m_key2); break; case Finish: visitor.finish(m_level); break; } }
int main() { // 1 + 1 // vector<string> l; // l.push_back("1"); // l.push_back("+"); // l.push_back("1"); // 2 * ( 1 + 1 ) vector<string> l; l.push_back("2"); l.push_back("*"); l.push_back("("); l.push_back("1"); l.push_back("+"); l.push_back("1"); l.push_back(")"); l.push_back("+"); l.push_back("123123"); LexerStream stream(l); Parser parser; parser.expr(&stream); // cout << endl; // cout << parser.code.front(); long usetime = timeTick([&](){ int count = 100000; while(count-- != 0) { int r = 2 * (1+1) + 123123; (void)r; } }); cout << endl; cout << "usetime:" << usetime; cout << endl; usetime = timeTick([&](){ int count = 100000; Calculator calculator; while(count-- != 0) { calculator.code = parser.code; calculator.result(); } }); cout << endl; cout << "usetime:" << usetime; cout << endl; //--------------------------- usetime = timeTick([&](){ int count = 100000; Visitor visitor; while(count-- != 0) { visitor.clear(); parser.asttree.astNode->accept(&visitor); } }); cout << endl; cout << "usetime:" << usetime; cout << endl; // Calculator calculator; // calculator.code = parser.code; // cout << calculator.result(); // Visitor visitor; // parser.asttree.astNode->accept(&visitor); // std::cout << std::endl; // visitor.print(); }