-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cpp
More file actions
executable file
·46 lines (33 loc) · 887 Bytes
/
Program.cpp
File metadata and controls
executable file
·46 lines (33 loc) · 887 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
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Program.hpp"
Program::Program(std::string* lines, int lineCount) : Segment(*(new VariableHashMap()), 0, Statement::PROGRAM){
int lineNumber = 0;
while(lineNumber < lineCount) {
try {
statements.add(Parser::parse(lines, lineCount, lineNumber, variables, scope));
} catch(ListException&) {
std::cout << "Exception caught in program" << std::endl;
std::cout << lineCount << std::endl;
}
}
//print();
execute();
}
Program::~Program() {
delete &variables;
}
void Program::execute() {
ListIterator<Statement>* it = statements.getIterator();
while(it->hasMore()) {
it->getValue()->execute();
it->next();
}
delete it;
}
void Program::print() {
ListIterator<Statement>* sIt = statements.getIterator();
while(sIt->hasMore()) {
sIt->getValue()->print();
sIt->next();
}
delete sIt;
}