more work on plasma parser
This commit is contained in:
44
AST.py
Normal file
44
AST.py
Normal 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": []
|
||||
}
|
||||
Reference in New Issue
Block a user