From eaa6c4562d8257e43a2a570c64cb7cd35a1f7c3b Mon Sep 17 00:00:00 2001 From: LtWorf Date: Fri, 19 Mar 2010 16:37:53 +0000 Subject: [PATCH] - Added printtree function to print an indented representation of the tree git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@221 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/parser.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/relational/parser.py b/relational/parser.py index ec4512a..0f38f04 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -105,8 +105,22 @@ class node (object): else: return self.name pass + def printtree(self,level=0): + '''Prints a representation of the tree using indentation''' + r='' + for i in range(level): + r+=' ' + r+=self.name + if self.name in b_operators: + r+=self.left.printtree(level+1) + r+=self.right.printtree(level+1) + elif self.name in u_operators: + r+='\t%s\n' % self.prop + r+=self.child.printtree(level+1) + + return '\n'+r def get_left_leaf(self): - '''This function returns the most left random leaf in the tree. It is needed by some optimizations.''' + '''This function returns the most left leaf in the tree. It is needed by some optimizations.''' if self.kind==RELATION: return self elif self.kind==UNARY: