-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoopCommand.cpp
More file actions
54 lines (50 loc) · 1.23 KB
/
Copy pathLoopCommand.cpp
File metadata and controls
54 lines (50 loc) · 1.23 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
//
// Created by yuvalshechter on 04/01/2020.
//
#include <mutex>
#include "LoopCommand.h"
LoopCommand:: LoopCommand(symbolTables* sT){
st = sT;
}
int LoopCommand::execute(int i) {
mutex m;
bool lock = m.try_lock();
if (!lock) {
cout << "unable to lock mutex in LoopCommand" <<endl;
}
varName = vec[i+1];
op = vec[i+2];
val = stof(vec[i+3]);
int endScope = setCommandsScope(i);
//int k = i;
while (isSatisfied()) {
int n = i+6;
for (unsigned int j=0;j<commands.size();j++) {
//Command* cScope = cmdMap[scopeVec[j]];
n = n + commands[j]->execute(n);
}
}
m.unlock();
return endScope;
}
int LoopCommand::setCommandsScope(int index) {
//find end of scope
commands.clear();
int j = index;
int scopeSize = 0;
while (vec[j] != "}") {
string word = vec[j];
if(word[0]=='\t'){
//erasing tab
word.erase(0,1);
if (!cmdMap[word] && vec[j+1] == "=") {
commands.push_back(cmdMap[vec[j+1]]);
} else if (cmdMap[word]) {
commands.push_back(cmdMap[word]);
}
}
j++;
scopeSize++;
}
return scopeSize+2;
}