-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLispInterpreter.cpp
More file actions
112 lines (83 loc) · 2.79 KB
/
LispInterpreter.cpp
File metadata and controls
112 lines (83 loc) · 2.79 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <fstream>
#include <vector>
#include "Token.h"
#include "Tokenizer.h"
#include "Exceptions.h"
#include "BlockManager.h"
#include "StatementManager.h"
#include "NumExprManager.h"
#include "BoolExprManager.h"
#include "Exceptions.h"
#include "Parser.h"
#include "Visitor.h"
#include "SymbolTable.h"
//#define DEBUG_MODE
//#define PRE_PRODUCTION
//#define POST_PRODUCTION
using namespace std;
int main(int argc, char** argv) {
if (argc < 2) {
cerr << "File non specificato" << endl;
cerr << "Utilizzare: " << argv[0] << " <nome_file>" << endl;
return EXIT_FAILURE;
}
/*** APERTURA FILE ***/
ifstream inputFile;
try {
inputFile.open(argv[1]);
}
catch (std::exception& exc) {
cerr << "Non posso aprire " << argv[1] << std::endl;
cerr << exc.what() << std::endl;
return EXIT_FAILURE;
}
/*** FASE DI TOKENIZZAZIONE ***/
Tokenizer tokenize;
std::vector<Token> inputTokens;
try {
inputTokens = tokenize((inputFile));
inputFile.close();
}
catch (LexicalError& le) {
cerr << "Errore in fase di analisi lessicale" << std::endl;
cerr << le.what() << std::endl;
return EXIT_FAILURE;
}
catch (SintaxError& se) {
cerr << "Errore sintattico" << std::endl;
cerr << se.what() << std::endl;
return EXIT_FAILURE;
}
catch (std::exception& exc) {
cerr << "Non posso leggere da " << argv[1] << std::endl;
cerr << exc.what() << std::endl;
return EXIT_FAILURE;
}
//creto i Manager necessari per il Parser
BlockManager BLManager;
StatementManager STManager;
NumExprManager NEManager;
BoolExprManager BEManager;
//// Creo il function object per il parsing
Parser parser(BLManager, STManager, NEManager, BEManager);
//*** FASE DI PARSING ***//
try {
Block* block = parser(inputTokens);
//cout << std::endl;
EvaluationVisitor* v = new EvaluationVisitor();
//cout << "Console outoput: " << endl;
block->accept(v);
}
catch (SemanticalError& exc) {
cerr << "ERROR in fase di Evaluation" << endl;
cerr << exc.what() << endl;
return EXIT_FAILURE;
}
catch (exception& exc) {
cerr << "ERROR in fase di Parsing" << endl;
cerr << exc.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}