VARIABLESSSS
This commit is contained in:
32
AST.py
32
AST.py
@@ -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
|
||||
Reference in New Issue
Block a user