-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.cpp
More file actions
77 lines (75 loc) · 2.58 KB
/
app.cpp
File metadata and controls
77 lines (75 loc) · 2.58 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
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include "function_actions.h"
#include "alpha_parser.hpp"
#include "error_handler.h"
#include "TreeHost.h"
#include "UnparseTreeVisitor.h"
#include "GraphTreeVisitor.h"
#include "Interpreter.h"
#include "ASTCreator.h"
#define BON "\e[1m"
#define BOFF "\e[0m"
//#define PHASE1
extern bool errorExists;
int main(int argc, char** argv) {
std::ifstream ifs;
std::ofstream ofs;
Object *astRoot = nullptr;
if (argc > 1) {
error_handler_init(argv[1]);
ifs.open(argv[1], std::ios::in);
if (!ifs.is_open()) {
//fprintf(stderr, "Unable to open input file \n");
error(ErrorType::FatalError, 0, "Unable to open input file " BON "\'%s\'" BOFF "\n", argv[1]);
return 1;
}
if (argc > 2) {
ofs.open(argv[2], std::ios::out);
if (!ofs.is_open()) {
//fprintf(stderr, "Unable to open output file\n");
error(ErrorType::FatalError, 0, "Unable to open output file " BON "\'%s\'" BOFF "\n", argv[2]);
return 2;
}
astRoot = ASTCreator::parseToAST(false, &ifs, &ofs);
} else {
astRoot = ASTCreator::parseToAST(false, &ifs);
}
} else {
const char * dfname = "stdin";
error_handler_init(dfname);
astRoot = ASTCreator::parseToAST(false);
}
if (!errorExists) {
/*
UnparseTreeVisitor unparsevis = UnparseTreeVisitor();
GraphTreeVisitor graphvis = GraphTreeVisitor();
TreeHost host = TreeHost();
host.accept(&unparsevis, *astRoot);
host.accept(&graphvis, *astRoot);
if (argc > 2) {
std::ofstream ofs1;
std::ofstream ofs2;
ofs1.open(std::string(argv[2]) + "_unparse.txt", std::ios::out);
ofs2.open(std::string(argv[2]) + "_graph.txt", std::ios::out);
ofs1 << unparsevis.getSourceText() << std::endl;
ofs2 << graphvis.getGraph() << std::endl;
} else {
std::cout << unparsevis.getSourceText() << std::endl;
std::cout << "-------------------------------------------" << std::endl;
std::cout << graphvis.getGraph() << std::endl;
}
*/
ASTCreator::validateAST(astRoot);
EvalDispatcher e;
Interpreter appInterpreter(&e);
ASTCreator::setInterpreterToUse(&appInterpreter);
ASTCreator::interpretAST(astRoot);
ASTCreator::destroyAST(astRoot);
error_handler_destroy();
}
ifs.close();
ofs.close();
return 0;
}