Fix loops
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
let int myNum 1;
|
let int myNum 1;
|
||||||
|
|
||||||
while myNum != 1001 {
|
while myNum != 1000 {
|
||||||
println myNum;
|
println myNum;
|
||||||
myNum = myNum + 1;
|
myNum = myNum + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
println "The loop has ended";
|
println "Finished";
|
||||||
|
@@ -249,20 +249,17 @@ void Interpreter::executeCode(vector<Token> tokens) {
|
|||||||
if (skipScope > 0) {
|
if (skipScope > 0) {
|
||||||
int braceCount = 0;
|
int braceCount = 0;
|
||||||
while (i < tokens.size()) {
|
while (i < tokens.size()) {
|
||||||
int braceCount = 0;
|
if (tokens[i].keyword == keywords::OBRAC) {
|
||||||
while (i < tokens.size()) {
|
braceCount ++;
|
||||||
if (tokens[i].keyword == keywords::OBRAC) {
|
} else if (tokens[i].keyword == keywords::CBRAC) {
|
||||||
braceCount ++;
|
if (braceCount == 0) {
|
||||||
} else if (tokens[i].keyword == keywords::CBRAC) {
|
skipScope --;
|
||||||
if (braceCount == 0) {
|
break;
|
||||||
skipScope --;
|
} else {
|
||||||
break;
|
braceCount --;
|
||||||
} else {
|
|
||||||
braceCount --;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (repeatScope > 0) {
|
if (repeatScope > 0) {
|
||||||
@@ -414,10 +411,18 @@ void Interpreter::executeCode(vector<Token> tokens) {
|
|||||||
loop = tokenIndex - 2 - lengthOfLine;
|
loop = tokenIndex - 2 - lengthOfLine;
|
||||||
repeatScope ++;
|
repeatScope ++;
|
||||||
log.debug("While loop condition is true, will skip back to " + to_string(loop));
|
log.debug("While loop condition is true, will skip back to " + to_string(loop));
|
||||||
|
} else if (!get<bool>(tokens[i].value.value)) {
|
||||||
|
int braceLevel = 0;
|
||||||
|
while (++i < tokens.size()) {
|
||||||
|
if (tokens[i].keyword == keywords::OBRAC) braceLevel ++;
|
||||||
|
else if (tokens[i].keyword == keywords::CBRAC) {
|
||||||
|
if (braceLevel == 0) break;
|
||||||
|
braceLevel --;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Condition is false, skipping scope");
|
syntaxError.generalError("Achievement get: How did we get here?");
|
||||||
skipScope ++;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tokens[i].keyword == keywords::VALUE && tokens[i].value.type == valtype::STR && variables.find(get<string>(tokens[i].value.value)) != variables.end()) {
|
if (tokens[i].keyword == keywords::VALUE && tokens[i].value.type == valtype::STR && variables.find(get<string>(tokens[i].value.value)) != variables.end()) {
|
||||||
|
Reference in New Issue
Block a user