-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.cpp
35 lines (32 loc) · 1.02 KB
/
test2.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
#include "src/LexicalAnalysis.hpp"
#include "src/GrammarAnalysis.hpp"
#include <fstream>
#include <iostream>
using namespace std;
int main() {
for (int i = 0; i <= 15; ++i) {
ifstream fin("test/test" + to_string(i) + ".txt");
ofstream fout("test/out/syntaxOut" + to_string(i) + ".txt");
if (!fin.is_open() || !fout.is_open()) {
cout << "failed to open file" << endl;
return 0;
}
LexicalAnalysis lexicalAnalysis(fin);
vector<Token> vec = lexicalAnalysis.scan();
bool error = false;
for (auto &token : vec) {
if (token.type == TokenType::ERROR) {
fout << "line: " << token.lineNo << " " << token.value << endl;
error = true;
}
}
if (error) continue;
GrammarAnalysis grammarAnalysis(vec, fout);
try {
grammarAnalysis.parse();
} catch (exception &e) { continue; }
grammarAnalysis.print();
fin.close();
fout.close();
}
}