Skip to content

Commit

Permalink
Add Ast class (#29)
Browse files Browse the repository at this point in the history
* chore: add `Ast`class

* chore: PR comments
  • Loading branch information
Nirei authored Jan 8, 2025
1 parent 3b6e05a commit 1d42248
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect

from bindings import Bindings
from parser import Ast


class UnknownSubroutine(Exception):
Expand All @@ -12,7 +13,7 @@ class InvalidMemoryAddressException(Exception):


class ImperivmExecutor:
def __init__(self, ast):
def __init__(self, ast: Ast):
self.subroutines = {}
self.stack = []
self.heap = []
Expand Down
15 changes: 13 additions & 2 deletions src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
import preprocessor


class Ast:
def __init__(self, tree: tuple):
self.tree = tree

def __iter__(self):
return self.tree.__iter__()

def __repr__(self):
return self.tree.__repr__()


class ImperivmParser:
def __init__(
self,
Expand All @@ -18,10 +29,10 @@ def __init__(
self.visitor = visitor
self.preprocessor = preprocessor

def parse(self, program):
def parse(self, program: str):
program = self.preprocessor.process(program)
tree = self.grammar.parse(program)
return self.visitor.visit(tree)
return Ast(self.visitor.visit(tree))


if __name__ == "__main__":
Expand Down

0 comments on commit 1d42248

Please sign in to comment.