RETURNING WORKSSSSS
This commit is contained in:
@@ -3,17 +3,37 @@ from typing import Any
|
||||
from ground_ast import *
|
||||
|
||||
|
||||
class SymbolTable:
|
||||
def __init__(self, parent=None):
|
||||
self.table = {} # variable name -> info (e.g., stack offset, type)
|
||||
self.parent = parent
|
||||
|
||||
def define(self, name, value):
|
||||
self.table[name] = value
|
||||
|
||||
def lookup(self, name):
|
||||
scope = self
|
||||
while scope:
|
||||
if name in scope.table:
|
||||
return scope.table[name]
|
||||
scope = scope.parent
|
||||
return None
|
||||
#raise KeyError(f"Undefined variable: {name}")
|
||||
|
||||
|
||||
class Generator:
|
||||
def __init__(self, ast: RootNode, code: str, output_path: str):
|
||||
self.ast = ast
|
||||
self.lines: list[str] = []
|
||||
self.code = code
|
||||
self.output_path = output_path
|
||||
self.variables = {}
|
||||
self.global_scope = SymbolTable()
|
||||
self.current_var_scope = self.global_scope
|
||||
self.constants = {}
|
||||
self.structs = {}
|
||||
self.functions: dict[str, FunctionNode] = {}
|
||||
self.labels = []
|
||||
self.arg_list = []
|
||||
self.constants_reverse = {}
|
||||
self.constant_counter = 0
|
||||
|
||||
|
Reference in New Issue
Block a user