-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz--.cpp
More file actions
92 lines (73 loc) · 1.98 KB
/
z--.cpp
File metadata and controls
92 lines (73 loc) · 1.98 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
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
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstring>
#include <memory>
#include <cstdlib>
#include <chrono>
#include "h/lexer.h"
#include "h/parser.h"
#include "h/errors/lexer.h"
using namespace std;
using namespace std::chrono;
LexerError lexerError;
int main(int argc, char* argv[]) {
auto start = high_resolution_clock::now();
if (argc < 2) {
cerr << "Usage: ab7 filename" << endl;
return 1;
}
string filename = argv[1];
ifstream file(filename);
if (!file.is_open()) {
cerr << "Error: Could not open file " << filename << endl;
return 1;
}
vector<string> lines;
string line;
while (getline(file, line)) {
lines.push_back(line);
}
file.close();
vector<vector<Token>> allTokens;
// Lexer
int lineNo = 1;
stack<char> punctuators;
for (const auto& line : lines) {
char* lineStr = const_cast<char*>(line.c_str());
vector<Token> tks = lexer(lineStr, lineNo, punctuators);
allTokens.push_back(tks);
lineNo++;
}
if(!punctuators.empty())
{
lexerError.UnclosedPunc(punctuators.top());
exit(EXIT_FAILURE);
}
// Lexer
// init file
ofstream outputFile("output.cpp");
if (outputFile.is_open()) {
outputFile << "using namespace std;" << endl;
outputFile << endl;
outputFile.close();
} else {
cerr << "Error: Unable to open output.cpp for writing." << endl;
}
// init file
// Parser
for (const auto& tks : allTokens) {
parser(tks);
}
// Parser
// Compile and execute
system("g++ output.cpp -o output.exe");
system("output.exe");
// system("rm -f output.exe output.cpp");
// Compile and execute
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout << "\nExecution Time: " << duration.count() << " microseconds" << endl;
return 0;
}