Skip to content

Commit 18ef840

Browse files
committed
✨ Interpreter support for while loops
1 parent c269ce8 commit 18ef840

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

PascalInterpreter/PascalInterpreter/Interpreter/Interpreter.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class Interpreter {
4848
return eval(ifElse: ifElse)
4949
case let repeatUntil as RepeatUntil:
5050
return eval(repeatUntil: repeatUntil)
51+
case let whileLoop as While:
52+
return eval(whileLoop: whileLoop)
5153
case let forLoop as For:
5254
return eval(forLoop: forLoop)
5355
default:
@@ -182,6 +184,14 @@ public class Interpreter {
182184
return .none
183185
}
184186

187+
func eval(whileLoop: While) -> Value {
188+
while case .boolean(true) = eval(condition: whileLoop.condition) {
189+
eval(node: whileLoop.statement)
190+
}
191+
192+
return .none
193+
}
194+
185195
func eval(forLoop: For) -> Value {
186196
guard let currentFrame = callStack.peek() else {
187197
fatalError("No call stack frame")

0 commit comments

Comments
 (0)