|
|
@ -121,14 +121,11 @@ class Node:
|
|
|
|
|
|
|
|
|
|
|
|
def printtree(self, level: int = 0) -> str:
|
|
|
|
def printtree(self, level: int = 0) -> str:
|
|
|
|
'''returns a representation of the tree using indentation'''
|
|
|
|
'''returns a representation of the tree using indentation'''
|
|
|
|
r = ''
|
|
|
|
r = ' ' * level + self.name
|
|
|
|
for i in range(level):
|
|
|
|
if self.name in b_operators and isinstance(self, Binary):
|
|
|
|
r += ' '
|
|
|
|
|
|
|
|
r += self.name
|
|
|
|
|
|
|
|
if self.name in b_operators:
|
|
|
|
|
|
|
|
r += self.left.printtree(level + 1)
|
|
|
|
r += self.left.printtree(level + 1)
|
|
|
|
r += self.right.printtree(level + 1)
|
|
|
|
r += self.right.printtree(level + 1)
|
|
|
|
elif self.name in u_operators:
|
|
|
|
elif self.name in u_operators and isinstance(self, Unary):
|
|
|
|
r += '\t%s\n' % self.prop
|
|
|
|
r += '\t%s\n' % self.prop
|
|
|
|
r += self.child.printtree(level + 1)
|
|
|
|
r += self.child.printtree(level + 1)
|
|
|
|
return '\n' + r
|
|
|
|
return '\n' + r
|
|
|
|