-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
67 lines (55 loc) · 1.55 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
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include "tokens.h"
#include "gettoken.h"
#include "parse.h"
#include "tree.h"
using namespace std;
int val = 0;
istream *us1 = &cin;
ifstream inFile;
int main(int argc, const char *argv[]) {
for (int i = 1; i < argc; i++) {
string vari(argv[i]);
if (i == argc - 1) {
inFile.open(vari);
if (inFile.is_open() == false) {
cerr << "COULD NOT OPEN " << vari << endl;
return -1;
}
us1 = &inFile;
}
else {
cerr << "TOO MANY FILENAMES" << endl;
return -1;
}
}
ParseTree *mainTree = Prog(*us1, val);
if (mainTree != 0)
{
try {
mainTree->Eval();
}
catch (std::logic_error &e) {
cout << "RUNTIME ERROR " << e.what() << endl;
}
if (mainTree->NodeCount() != 0) {
cout << "NODE COUNT: " << mainTree->NodeCount() << endl;
}
if ((mainTree->NodeCount() - mainTree->leaves()) != 0) {
cout << "INTERIOR COUNT: " << (mainTree->NodeCount() - mainTree->leaves()) << endl;
}
if (mainTree->ops() != 0) {
cout << "OPS COUNT: " << mainTree->ops() << endl;
}
if (mainTree->strings() != 0) {
cout << "STRING COUNT: " << mainTree->strings() << endl;
}
if (mainTree->maxdepth() != 0) {
cout << "MAX DEPTH: " << mainTree->maxdepth() << endl;
}
}
return 0;
}