Repository navigation
Expand file tree
/
Copy pathProgram.cpp
More file actions
81 lines (62 loc) · 1.74 KB
/
Copy pathProgram.cpp
File metadata and controls
81 lines (62 loc) · 1.74 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
#include "Program.h"
unsigned int Program::itAllLines;
std::vector<Line*> Program::allLines;
std::map<int, Command*> Program::linejump;
std::stack<Line*> Program::allGoSub;
std::map<std::string, int> Program::allVariables;
std::map<std::string, std::map<int, int>* > Program::allArrays;
//implement Program class
Program::Program() {
Program::itAllLines = 0;
}
Program::~Program() {
/*
for (unsigned int i=0; i < Program::allLines.size(); i++) {
delete Program::allLines[i] -> c;
delete Program::allLines[i];
}
*/
}
void Program::addLine(int x, Command* _c) {
//add command to vector "allLines" and map "linejump"
Line* new_line = new Line(x, _c);
Program::allLines.push_back(new_line);
linejump[x] = _c;
}
//adding Variable array
void Program::addArray() {
//adding to the map of all variable arrays,
//where the key is the name and the value is a pointer
//to an ArithmeticExpression, which is a VarArray
}
//adding a Variable
void Program::addVariable(std::string s, int x) {
//adding to a map
//how to insert to a map?
//int x = ae->evaluate();
std::map<std::string, int>::iterator it = Program::allVariables.find(s);
if (it != Program::allVariables.end()) { //if pos already key in map
it->second = x;
}
else { //pos not key in map -- insert pair
//vararray->insert(pos, value);
//overwrite
Program::allVariables[s] = x;
}
}
//adding a GoSub
void Program::addGoSub(Line* l) {
Program::allGoSub.push(l);
}
//testing if GoSub empty
bool Program::GoSubEmpty() {
return Program::allGoSub.empty();
}
Line* Program::getGoSub() {
//if (GoSubEmpty()) {throw Error("No matching GOSUB for RETURN.");}
return Program::allGoSub.top();
}
//removing a GoSub from the stack
void Program::removeGoSub() {
Program::allGoSub.pop();
}