more work on plasma parser

This commit is contained in:
2025-10-13 13:09:48 +11:00
parent d4aa448712
commit 40d695729f
2 changed files with 60 additions and 1 deletions

44
AST.py Normal file
View File

@@ -0,0 +1,44 @@
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": []
}