while loops work!

This commit is contained in:
SpookyDervish
2025-10-15 18:44:15 +11:00
parent 549f650b54
commit 9f6fff9977
7 changed files with 155 additions and 86 deletions

16
AST.py
View File

@@ -13,6 +13,7 @@ class NodeType(Enum):
BlockStatement = "BlockStatement"
ReturnStatement = "ReturnStatement"
IfStatement = "IfStatement"
WhileStatement = "WhileStatement"
# Expressions
InfixExpression = "InfixExpression"
@@ -247,6 +248,21 @@ class IfStatement(Statement):
"consequence": self.consequence.json(),
"alternative": self.alternative.json() if self.alternative is not None else None
}
class WhileStatement(Statement):
def __init__(self, condition: Expression, body: BlockStatement = None):
self.condition = condition
self.body = body
def type(self) -> NodeType:
return NodeType.WhileStatement
def json(self) -> dict:
return {
"type": self.type().value,
"condition": self.condition.json(),
"body": self.body.json()
}
# endregion
# region Expressions