-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
41 lines (35 loc) · 962 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <fstream>
#include "SnlGrammarAnalyser.h"
using namespace std;
/**
* 将输入流读入为一个string
* @param in 输入流
* @return 输入流读入的所有内容
*/
string convertStreamToString(ifstream &in) {
string r, x;
while (getline(in, x)) {
r += x;
r += '\n';
}
return r;
}
int main() {
SnlGrammarAnalyser::init();
SnlGrammarAnalyser analyser;
for (int i = 1; i <= 8; i++) {
ifstream in;
in.open("../examples/C" + to_string(i) + ".TXT", ios::in);
string x = convertStreamToString(in);
in.close();
if (analyser.parse(x.c_str()) == 0) {
cout << i << " 词法检查通过! 语法检查通过!" << endl << endl;
cout << "语法树的DOT Language描述如下:" << endl << endl;
cout << analyser.getTree() << endl << endl;
} else {
cerr << i << " " << analyser.getError() << endl << endl;
}
}
return 0;
}