Jelajahi Sumber

make files for codegen

Johan Rong 1 bulan lalu
induk
melakukan
2a30eea626
2 mengubah file dengan 22 tambahan dan 1 penghapusan
  1. 6 1
      src/zelkelc/__main__.py
  2. 16 0
      src/zelkelc/codegen/codegen.py

+ 6 - 1
src/zelkelc/__main__.py

@@ -1,5 +1,6 @@
 from src.zelkelc.lexer.tokenizer import lex
 from src.zelkelc.ast.parser import Parser
+from src.zelkelc.codegen.codegen import Codegen
 
 import rich # type: ignore
 
@@ -24,4 +25,8 @@ if __name__ == "__main__":
     print(tokens)
     parser = Parser(tokens, 0)
     ast = parser.parse()
-    rich.print(ast)
+    rich.print(ast)
+    
+    codegen = Codegen(ast)
+    ir = codegen.generate()
+    print(ir)

+ 16 - 0
src/zelkelc/codegen/codegen.py

@@ -0,0 +1,16 @@
+import src.zelkelc.ast.nodes as nodes
+import src.zelkelc.ast.values as values
+
+class Codegen:
+    ast: list[nodes.FunctionDeclaration | nodes.ClassDeclaration]
+    
+    def __init__(self, ast: list[nodes.FunctionDeclaration | nodes.ClassDeclaration]):
+        self.ast = ast
+        
+    def generate(self) -> str:
+        ir = ""
+        
+        return ir
+
+    def gen_class_declaration(self) -> str:
+