ok we have basic decimal math 👍
This commit is contained in:
@@ -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":
|
||||
|
Reference in New Issue
Block a user