解释器(Interpreter)之大胆向MM示爱吧(四)
复制代码
1 #include
2 #include "expression.h"
3 #include "Translator.h"
4
5 using namespace std;
6
7 int main()
8 {
9 cout << "Input your command below: " << endl;
10 string str;
11 getline(cin, str);
12 Translator translator;
13
14 // ... Generate the Abstract Grammar Tree by Translator
15 Expression* myExp = translator.translate(str);
16 if (!myExp) return 1;
17
18 // ... Call Its Interpret Operation
19 stringstream ss;
20 myExp->eva l(ss);
21
22 cout << ss.str() << endl;
23 return 0;
24 }
复制代码
那么我们输入之前第二串字符试试:
复制代码
*****
**
** ****** **** **** *****
** ** ** ** ** ** **
** ** ** ** ** ********
## # ## ## ## ## ##
## # ## ## ### ## ##
####### ##### ## ######