-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (33 loc) · 1.09 KB
/
main.cpp
File metadata and controls
38 lines (33 loc) · 1.09 KB
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
#include <ratio>
#include <chrono>
#include "tokenizer.h"
#include "parser.h"
#include "vm.h"
int main() {
Error error;
Tokenizer tokenizer("testfile.txt", error);
// ofstream output("output.txt");
Parser parser(tokenizer.tokens, error);
// output << parser;
if (error.errors.empty()) {
ofstream result("pcoderesult.txt");
if (!result.is_open()) {
perror("Failed to create result file");
exit(EXIT_FAILURE);
}
StackMachine machine(parser.instructions, parser.sym_table.back(), result);
cout << machine;
auto start = chrono::high_resolution_clock::now();
machine.run();
chrono::duration<double, ratio<1, 1>> duration_s(chrono::high_resolution_clock::now() - start);
cout << "Process finished in " << duration_s.count() << " seconds" << endl;
} else {
ofstream error_stream("error.txt");
if (!error_stream.is_open()) {
perror("Failed to create error file");
exit(EXIT_FAILURE);
}
error_stream << error;
}
return EXIT_SUCCESS;
}