-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
34 lines (29 loc) · 774 Bytes
/
Copy pathprogram.cpp
File metadata and controls
34 lines (29 loc) · 774 Bytes
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
#include <iostream>
#include <cstdlib>
#include "exception.h"
#include "statement.h"
#include "function.h"
#include "program.h"
using std::cerr;
using std::endl;
Program::~Program() {
delete statementList;
}
int Program::eval() {
try {
// execute all statements in program
statementList->eval(st, ft);
// call the main function, if defined
Function* main = ft["main"];
if (main != NULL) {
main->apply(st, ft);
}
} catch (ParseException e) {
cerr << "error (line " << e.getLineNumber() << "): " << e.what() << endl;
return 2;
} catch (ReturnValue e) {
cerr << "error (line " << e.getLineNumber() << "): " << "return statement outside of function" << endl;
return 2;
}
return 0;
}