第一部份#include <iostream> #include <memory> #include <stack> #include <fstream> #include <vector> #include <cmath> #include <iomanip> #include <exception> #include <climits> #include <array> #include <cstdint> #include <string> using namespace std; class T { public: virtual bool isOperator() = 0; virtual ~T() {} }; class ValueToken : public T { public: long long value; long long get_value() { return value; } virtual bool isOperator() { return false; } explicit ValueToken(long long val) : value(val) {} }; class OperatorToken : public T { public: enum OpType { BGN = 0, END, ADD, MNS, NEG, MUL, DIV, POW, LBK, RBK } optr; virtual bool isOperator() { return true; } char get_char() { switch (optr) { case BGN: return '@'; case END: return '$'; case ADD: return '+'; case MNS: return '-'; case NEG: return '#'; case MUL: return '*'; case DIV: return '/'; case POW: return '^'; case LBK: return '('; case RBK: return ')'; default: return '?'; } } explicit OperatorToken(OperatorToken::OpType op) : optr(op) {} bool is_prior(const OperatorToken& r) { return prior_table[this->optr][r.optr]; } static bool prior_table[10][10]; }; bool OperatorToken::prior_table[10][10] = { //BGN, END, ADD, MNS, NEG, MUL, DIV, POW, LBK, RBK {0,0,0,0,0,0,0,0,0,0},//BGN {1,0,0,0,0,0,0,0,0,0},//END {1,1,0,0,0,0,0,0,1,0},//ADD {1,1,0,0,0,0,0,0,1,0},//MNS {1,1,1,1,0,1,1,1,1,0},//NEG {1,1,1,1,0,0,0,0,1,0},//MUL {1,1,1,1,0,0,0,0,1,0},//DIV {1,1,1,1,0,1,1,1,1,0},//POW {1,1,1,1,1,1,1,1,1,0},//LBK {1,1,0,0,0,0,0,0,1,0},//RBK };