VARIABLESSSS

This commit is contained in:
SpookyDervish
2025-10-13 21:05:03 +11:00
parent 4e17674361
commit f9cd1dba29
17 changed files with 366 additions and 65 deletions

32
AST.py
View File

@@ -7,6 +7,7 @@ class NodeType(Enum):
# Statements
ExpressionStatement = "ExpressionStatement"
AssignmentStatement = "AssignmentStatement"
# Expressions
InfixExpression = "InfixExpression"
@@ -14,6 +15,7 @@ class NodeType(Enum):
# Literals
IntegerLiteral = "IntegerLiteral"
FloatLiteral = "FloatLiteral"
IdentifierLiteral = "IdentifierLiteral"
class Node:
@abstractmethod
@@ -56,6 +58,23 @@ class ExpressionStatement(Statement):
"type": self.type().value,
"expr": self.expr.json()
}
class AssignmentStatement(Statement):
def __init__(self, name: Expression = None, value: Expression = None, value_type: str = None) -> None:
self.name = name
self.value = value
self.value_type = value_type
def type(self) -> NodeType:
return NodeType.AssignmentStatement
def json(self) -> dict:
return {
"type": self.type().value,
"name": self.name.json(),
"value": self.value.json(),
"value_type": self.value_type
}
# endregion
# region Expressions
@@ -103,4 +122,17 @@ class FloatLiteral(Expression):
"type": self.type().value,
"value": self.value
}
class IdentifierLiteral(Expression):
def __init__(self, value: str = None) -> None:
self.value: str = value
def type(self) -> NodeType:
return NodeType.IdentifierLiteral
def json(self) -> dict:
return {
"type": self.type().value,
"value": self.value
}
# endregion