needs refactoring
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
# (c) Stephan Diehl, University of Trier, Germany, 2025
|
||||
|
||||
class EXPRESSION:
|
||||
pp_count = 0
|
||||
|
||||
@@ -69,7 +67,7 @@ class DECL(EXPRESSION):
|
||||
self.body = body
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.f_name}(" + ",".join(str(p) for p in self.params) + ") { " + str(self.body) + " }"
|
||||
return f"{self.f_name}({self.params}) {{ {self.body} }}"
|
||||
|
||||
class CALL(EXPRESSION):
|
||||
def __init__(self, f_name, arguments):
|
||||
@@ -171,20 +169,4 @@ class WHILE(EXPRESSION):
|
||||
self.body = body
|
||||
|
||||
def __str__(self):
|
||||
return "while (" + str(self.condition) + ") do { " + str(self.body) + " }"
|
||||
|
||||
def pretty_print(clas, indent=0):
|
||||
print(' ' * indent + type(clas).__name__ + ':')
|
||||
indent += 4
|
||||
for k, v in clas.__dict__.items():
|
||||
if isinstance(v, EXPRESSION):
|
||||
pretty_print(v, indent)
|
||||
else:
|
||||
print(' ' * indent + f"{k}: {v}")
|
||||
|
||||
def export_dot(ast, filename="ast.dot"):
|
||||
with open(filename, "w") as f:
|
||||
f.write("digraph AST {\n")
|
||||
f.write(" node [shape=box];\n")
|
||||
ast.to_dot(f)
|
||||
f.write("}\n")
|
||||
return "while (" + str(self.condition) + ") do { " + str(self.body) + " }"
|
||||
Reference in New Issue
Block a user