parser isnt liking for statements :(
This commit is contained in:
45
AST.py
45
AST.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user