From e528a4babfe6e790841b38ed8cc50b4fbf737b80 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Tue, 28 Apr 2009 20:11:25 +0000 Subject: [PATCH] now handles futile nested parenthesis git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@132 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/optimizer.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/relational/optimizer.py b/relational/optimizer.py index 52c2f87..3e67024 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -33,14 +33,14 @@ class node (object): def __init__(self,expression): '''Generates the tree from the tokenized expression''' - if len(expression)==1: - if expression[0].__class__==[].__class__: #We have a list! + while len(expression)==1 and expression[0].__class__==[].__class__: #We have a list, removing expression=expression[0] - if len(expression)==1 and expression[0].__class__=="".__class__: #We have a string! - print "Relation: ",expression[0] - self.kind=RELATION - self.name=expression[0] - return + + if len(expression)==1 and expression[0].__class__=="".__class__: #We have a string! + print "Relation: ",expression[0] + self.kind=RELATION + self.name=expression[0] + return for i in range(len(expression)-1,-1,-1): #Expression from right to left if expression[i] in b_operators: #Binary operator print "Operator: ",expression[i] @@ -169,15 +169,15 @@ def tree(expression): return node(tokenize(expression)) if __name__=="__main__": - #n=node(u"((a ᑌ b) - c ᑌ d) - b") #n=node(u"((((((((((((2)))))))))))) - (3 * 5) - 2") #n=node(u"π a,b (d-a*b)") #print n.__str__() - a= tokenize("(a - (a ᑌ b) * π a,b (a-b)) - ρ 123 (a)") + #a= tokenize("(a - (a ᑌ b) * π a,b (a-b)) - ρ 123 (a)") #a= tokenize(u"π a,b (a*b)") #a=tokenize("(a-b*c)*(b-c)") + a=tokenize("((((((((a)))))))) * b -c ") print a print node(a) #print tokenize("(a)") \ No newline at end of file