-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (80 loc) · 2.63 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <cstring>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <iostream>
#include "UI/UI.hpp"
#include "exceptions/ArgsParsingException.hpp"
#include "exceptions/ParserException.hpp"
#include "exceptions/PreprocessorException.hpp"
#include "exceptions/RuntimeException.hpp"
#include "frontend/Parser.hpp"
#include "frontend/Preprocessor.hpp"
#include "frontend/StringUtils.hpp"
#include "instructions/Instruction.hpp"
#include "interpreter/Interpreter.hpp"
#include "tests/simple_instructions_test.hpp"
int main(int argc, char* argv[]) {
bool debug_mode = false;
bool graph_mode = false;
if (argc == 1) {
cout << "No incoming file" << endl;
exit(1);
}
const string file = argv[1];
try {
std::set<FLAGS> flags = StringUtils::parse_args(argc, argv);
if (flags.contains(d)) {
debug_mode = true;
}
if (flags.contains(g)) {
graph_mode = true;
}
} catch (const ArgsParsingExceprion& e) {
cout << e.get_message() << endl;
exit(1);
}
Preprocessor preprocessor = Preprocessor(file);
try {
preprocessor.preprocess();
} catch (const PreprocessorException& e) {
cout << e.get_message() << endl;
exit(1);
}
Lexer lexer(preprocessor.get_inparse());
Parser parser(lexer, preprocessor.get_labels(), preprocessor.get_from_inparse_to_in());
vector<Instruction*> instructions;
try {
instructions = parser.get_instructions();
} catch (const ParserException& e) {
cout << e.get_message() << endl;
exit(1);
}
auto all_lines_in = preprocessor.all_lines_in();
Interpreter controller(instructions, preprocessor.get_labels(), all_lines_in, preprocessor.get_from_in_to_inparse(),
preprocessor.get_from_inparse_to_in(), debug_mode, graph_mode);
if (graph_mode) {
UI ui(all_lines_in, debug_mode, controller);
ui.start();
} else {
try {
if (debug_mode && controller.has_lines()) {
controller.open_interface();
}
while (controller.has_lines()) {
controller.interpret();
if (debug_mode && controller.has_lines()) {
controller.open_interface();
}
}
if (debug_mode && controller.is_break()) {
controller.open_interface();
}
} catch (const RuntimeException& e) {
cout << e.get_message() << endl;
exit(1);
}
}
// preprocessor.dump_inparse();
// test_all();
return 0;
}