Added single line while loops

This commit is contained in:
Lukasz Baldyga committed 2020-12-03 23:19:28 +00:00
1 parent 40754aae69
commit 72b5db624f
2 files changed
+12

No files matched your search

@@ -13,6 +13,12 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
valueStorage.IncreaseStack();
}
public WhileChunk(ValueStorage valueStorage, IValue conditional, IVerb oneLineVerb) : base(new List<IVerb> { oneLineVerb }) {
this.conditional = conditional;
this.valueStorage = valueStorage;
valueStorage.IncreaseStack();
}
public new void ExecuteVerb() {
valueStorage.IncreaseStack();
while (conditional.ToBool()) base.ExecuteVerb();
@@ -104,6 +104,12 @@ namespace Advanced_Software_Engineering {
currentChunk = verbChunks[chunkDepth];
parsed = true;
tmpVerb = new NoOp();
} else if (commandParameters.Length >= 2) { //single line if
string commandAfterIf = fullCommand.Substring(fullCommand.IndexOf(",") + 1); // find the first ,
IValue conditional = ValueFactory.CreateValue(rootValueStorage, commandParameters[0]); //make the conditional
IVerb AfterIf = MakeVerb(drawer, commandAfterIf); //make the following command
tmpVerb = new WhileChunk(rootValueStorage, conditional, AfterIf); //Create the chunk
parsed = true;
} else throw new Exception(command + " has an incorrect number of parameters");
break;