-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
36 lines (30 loc) · 804 Bytes
/
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
#include <iostream>
#include <string>
#include <fstream>
#include "lexer.h"
#include "parser.h"
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 2) {
cerr << "File to read not specified" << endl;
return 0;
}
string file = argv[1];
ifstream stream(file);
if (!stream.is_open()) {
cerr << "Could not read the file provided" << endl;
return 0;
}
string line, expression;
while (getline(stream, line)) expression.append(line);
try {
auto tokens = Lexer(expression).tokenize();
auto tree = Parser(tokens).parse();
tree.optimize();
tree.evaluate();
} catch (const invalid_argument &e) {
cerr << e.what() << endl;
}
Operator::destroyMap();
Token::destroyMap();
}