ITS GENERATING AN EXECUTABLE LETS GOOOO

This commit is contained in:
SpookyDervish
2025-09-01 18:00:49 +10:00
parent 62e95a24ed
commit 88cdcfa54f
7 changed files with 91 additions and 16 deletions

View File

@@ -52,6 +52,9 @@ class LabelRefNode:
@dataclass
class LineRefNode:
line: int
@dataclass
class BoolNode:
value: bool
def generate_ast(tokens: list[Token], code: str) -> RootNode:
root_node = RootNode([])
@@ -97,6 +100,12 @@ def generate_ast(tokens: list[Token], code: str) -> RootNode:
else:
traceback(code, "SyntaxError", "Expected instruction, not string.")
elif token.type == TokenType.BOOL:
if current_node_type == "inst":
current_node.arguments.append(BoolNode(token.value))
else:
traceback(code, "SyntaxError", "Expected instruction, not string.")
elif token.type == TokenType.INTEGER or token.type == TokenType.FLOAT:
if current_node_type == "inst":
current_node.arguments.append(NumberNode(token.value))
@@ -154,6 +163,9 @@ def generate_ast(tokens: list[Token], code: str) -> RootNode:
elif token.type == TokenType.LABEL_DECLERATION:
scope.statements.append(LabelDecNode(token.value))
elif token.type == TokenType.COMMENT:
continue
elif token.type == TokenType.EOF:
root_node.statements.append(current_node)