This repository was archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (56 loc) · 1.78 KB
/
Copy pathmain.cpp
File metadata and controls
59 lines (56 loc) · 1.78 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <string>
#include "lexer.h"
#include "parser.h"
#include "semantics.h"
using namespace std;
//main is currently configured to output only parser data
int main(int argc, char** argv) {
lexer rat18s_lex = lexer();
parser rat18s_par = parser();
semantic rat18s_sem = semantic();
string file_to_process;
string target_file;
fstream input_file;
ofstream output_file;
bool good;
if (argc < 3) {
cout << "USAGE: " << argv[0] << " <input file name> <output file name>" << endl;
}
else {
cout << "Starting compilation process. . ." << endl;
file_to_process = string(argv[1]);
target_file = string(argv[2]);
cout << "Processing file: " << file_to_process << endl;
cout << "Saving compilation output to file: " << target_file << endl;
input_file.open(file_to_process);
cout << "Tokenizing. . ." << endl;
rat18s_lex.process_file(input_file);
output_file.open(target_file);
cout << "Checking tokens. . ." << endl;
good = rat18s_lex.check_tokens();
if (good) {
rat18s_par.initialize_parse();
good = rat18s_par.parse(rat18s_lex);
}
if (good) {
good = rat18s_sem.exec_semantics(rat18s_par.get_semantics());
}
if (good) {
rat18s_sem.print_instructions(output_file, false);
output_file << endl << "SYMBOL TABLE" << endl;
rat18s_sem.print_table(output_file, false);
}
output_file.close();
input_file.close();
if (!good) {
cout << "Compilation failed." << endl;
}
else {
output_file << "Done." << endl;
cout << "Done." << endl;
}
}
return 0;
}