ok we have basic decimal math 👍

This commit is contained in:
SpookyDervish
2025-09-04 07:45:20 +10:00
parent 42e718d6d3
commit 459f53a4e1
8 changed files with 162 additions and 72 deletions

View File

@@ -19,10 +19,15 @@ class StringNode:
def __repr__(self):
return "String"
@dataclass
class NumberNode:
class IntNode:
value: float
def __repr__(self):
return "Number"
return "Int"
@dataclass
class FloatNode:
value: float
def __repr__(self):
return "Float"
@dataclass
class VarRefNode:
var_name: str
@@ -126,11 +131,17 @@ def generate_ast(tokens: list[Token], code: str) -> RootNode:
else:
traceback(code, "SyntaxError", "Expected instruction, not string.")
elif token.type == TokenType.INTEGER or token.type == TokenType.FLOAT:
elif token.type == TokenType.INTEGER:
if current_node_type == "inst":
current_node.arguments.append(NumberNode(token.value))
current_node.arguments.append(IntNode(token.value))
else:
traceback(code, "SyntaxError", "Expected instruction, not number.")
traceback(code, "SyntaxError", "Expected instruction, not integer.")
elif token.type == TokenType.FLOAT:
if current_node_type == "inst":
current_node.arguments.append(FloatNode(token.value))
else:
traceback(code, "SyntaxError", "Expected instruction, not float.")
elif token.type == TokenType.LINE_REFERENCE:
if current_node_type == "inst":