From: NilsForssen Date: Mon, 9 Oct 2023 10:25:49 +0000 (+0200) Subject: Added main file X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=28e5d26424b80cb2cb6995b1cf572594a823a03d;p=TDDC76.git Added main file --- diff --git a/src/uppgift13.cc b/src/uppgift13.cc index fb82a08..d5252f5 100644 --- a/src/uppgift13.cc +++ b/src/uppgift13.cc @@ -1,15 +1,51 @@ #include +#include "expression.h" -using namespace std; +typedef enum +{ + PREFIX, + INFIX, + POSTFIX, + CALC, + QUIT +} Commands; + +std::map commands_string_map; int main() { - string line; - while ( getline(cin, line) ) + std::string line; + std::cout << "Write expression: "; + + std::getline(std::cin, line); + Expression e{line}; + + while (std::getline(std::cin, line)) { - Expression e{line}; - cout << e.to_string() << endl - << e.evaluate() << endl; + if (line == ":prefix") + { + std::cout << e.to_prefix_string() << std::endl; + } + else if (line == ":infix") + { + std::cout << e.to_infix_string() << std::endl; + } + else if (line == ":postfix") + { + std::cout << e.to_postfix_string() << std::endl; + } + else if (line == ":calc") + { + std::cout << "Value: " << e.evaluate() << std::endl; + } + else if (line == ":quit") + { + break; + } + else + { + Expression e{line}; + } } return 0; }