-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIfCommand.cpp
More file actions
47 lines (44 loc) · 1 KB
/
Copy pathIfCommand.cpp
File metadata and controls
47 lines (44 loc) · 1 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
//
// Created by yuvalshechter on 05/01/2020.
//
#include <mutex>
#include "IfCommand.h"
IfCommand::IfCommand(symbolTables *sT) {
st = sT;
}
int IfCommand::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;
if (isSatisfied()) {
unsigned int n = i+6;
for (unsigned int j=0;j<commands.size();j++) {
n = n + commands[j]->execute(n);
}
}
m.unlock();
return endScope;
}
int IfCommand::setCommandsScope(int index) {
//find end of scope
unsigned int j = index;
int scopeSize = 0;
while (vec[j] != "}") {
string word = vec[j];
if(word[0]=='\t'){
//erasing tab
word.erase(0,1);
commands.push_back(cmdMap[word]);
}
j++;
scopeSize++;
}
return scopeSize+2;
}