44 lines
818 B
Python
44 lines
818 B
Python
from abc import ABC, abstractmethod
|
|
from enum import Enum
|
|
|
|
|
|
class NodeType(Enum):
|
|
Program = "Program"
|
|
|
|
# Statements
|
|
ExpressionStatement = "ExpressionStatement"
|
|
|
|
# Expressions
|
|
InfixExpression = "InfixExpression"
|
|
|
|
# Literals
|
|
IntegerLiteral = "IntegerLiteral"
|
|
FloatLiteral = "FloatLiteral"
|
|
|
|
class Node:
|
|
@abstractmethod
|
|
def type(self) -> NodeType:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def json(self) -> dict:
|
|
pass
|
|
|
|
class Statement(Node):
|
|
pass
|
|
|
|
class Expression(Node):
|
|
pass
|
|
|
|
class Program(Node):
|
|
def __init__(self) -> None:
|
|
self.statements: list[Statement] = []
|
|
|
|
def type(self) -> NodeType:
|
|
return NodeType.Program
|
|
|
|
def json(self) -> dict:
|
|
return {
|
|
"type": self.type().value,
|
|
"statements": []
|
|
} |