while loops work!
This commit is contained in:
16
AST.py
16
AST.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user