now handles futile nested parenthesis

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@132 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
LtWorf 2009-04-28 20:11:25 +00:00
parent 1060e9d275
commit e528a4babf

View File

@ -33,9 +33,9 @@ class node (object):
def __init__(self,expression): def __init__(self,expression):
'''Generates the tree from the tokenized expression''' '''Generates the tree from the tokenized expression'''
if len(expression)==1: while len(expression)==1 and expression[0].__class__==[].__class__: #We have a list, removing
if expression[0].__class__==[].__class__: #We have a list!
expression=expression[0] expression=expression[0]
if len(expression)==1 and expression[0].__class__=="".__class__: #We have a string! if len(expression)==1 and expression[0].__class__=="".__class__: #We have a string!
print "Relation: ",expression[0] print "Relation: ",expression[0]
self.kind=RELATION self.kind=RELATION
@ -169,15 +169,15 @@ def tree(expression):
return node(tokenize(expression)) return node(tokenize(expression))
if __name__=="__main__": if __name__=="__main__":
#n=node(u"((a b) - c d) - b") #n=node(u"((a b) - c d) - b")
#n=node(u"((((((((((((2)))))))))))) - (3 * 5) - 2") #n=node(u"((((((((((((2)))))))))))) - (3 * 5) - 2")
#n=node(u"π a,b (d-a*b)") #n=node(u"π a,b (d-a*b)")
#print n.__str__() #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(u"π a,b (a*b)")
#a=tokenize("(a-b*c)*(b-c)") #a=tokenize("(a-b*c)*(b-c)")
a=tokenize("((((((((a)))))))) * b -c ")
print a print a
print node(a) print node(a)
#print tokenize("(a)") #print tokenize("(a)")