-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpreter.cpp
More file actions
54 lines (49 loc) · 1.06 KB
/
Copy pathinterpreter.cpp
File metadata and controls
54 lines (49 loc) · 1.06 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
/*
* main.cpp
*
* Lucas Bastos
* CS280
* Spring 2020
*/
#include "lex.h"
#include "parse.h"
#include "pt.h"
#include "lexeme.cpp"
#include "parse.cpp"
#include "val.h"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
map<string, Value> symbols;
int main(int argc, char *argv[]) {
istream *in = &cin;
int lineNumber = 0, fileCount = 0;
string filename;
for (int i = 1; i < argc; i++) {
string flag = argv[i];
if (fileCount == 0 && i == argc-1) {
filename = flag;
fileCount++;
} else {
cout << "ONLY ONE FILE NAME ALLOWED" << endl;
return 0;
}
}
ifstream input(filename);
if (fileCount == 1) {
if (!input.is_open()) {
cout << "CANNOT OPEN " << filename << endl;
return 0;
}
in = &input;
}
Pt *tree = Prog(*in, lineNumber);
if (tree) {
try {
tree->Eval(symbols);
} catch (const std::exception &e) {
cout << e.what() << endl;
}
}
}