parser isnt liking for statements :(

This commit is contained in:
SpookyDervish
2025-10-16 07:24:40 +11:00
parent 9f6fff9977
commit 600bebb9b2
6 changed files with 153 additions and 11 deletions

45
AST.py
View File

@@ -14,6 +14,9 @@ class NodeType(Enum):
ReturnStatement = "ReturnStatement"
IfStatement = "IfStatement"
WhileStatement = "WhileStatement"
BreakStatement = "BreakStatement"
ContinueStatement = "ContinueStatement"
ForStatement = "ForStatement"
# Expressions
InfixExpression = "InfixExpression"
@@ -263,6 +266,48 @@ class WhileStatement(Statement):
"condition": self.condition.json(),
"body": self.body.json()
}
class BreakStatement(Statement):
def __init__(self) -> None:
pass
def type(self) -> NodeType:
return NodeType.BreakStatement
def json(self) -> dict:
return {
"type": self.type().value
}
class ContinueStatement(Statement):
def __init__(self) -> None:
pass
def type(self) -> NodeType:
return NodeType.ContinueStatement
def json(self) -> dict:
return {
"type": self.type().value
}
class ForStatement(Statement):
def __init__(self, var_declaration: AssignmentStatement = None, condition: Expression = None, action: ReassignStatement = None, body: BlockStatement = None) -> None:
self.var_declaration = var_declaration
self.condition = condition
self.action = action
self.body = body
def type(self) -> NodeType:
return NodeType.ForStatement
def json(self) -> dict:
return {
"type": self.type().value,
"var_declaration": self.var_declaration.json(),
"condition": self.condition.json(),
"body": self.body.json()
}
# endregion
# region Expressions