diff --git a/CHANGELOG b/CHANGELOG index 410f1a3..b04d5f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -63,4 +63,6 @@ - Default source package now doesn't contain informations to generate debian/mac packages - "make source_all" generates the old style tarball containing all the files - Bug: relational script installed with debian package now passes arguments to the python executable -- Insert and delete from GUI are now done on the displayed relation, not on the selected one \ No newline at end of file +- Insert and delete from GUI are now done on the displayed relation, not on the selected one + +0.10 \ No newline at end of file diff --git a/relational/optimizer.py b/relational/optimizer.py index 813e0d1..54d2597 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -127,6 +127,47 @@ class node (object): return (left+ self.name +right) +def parseList(expression): + '''This function converts an expression into a list where + every token of the expression is an item of a list. Expressions into + parenthesis will be converted into sublists.''' + items=[] #List for the tokens + par_count=0 #Count of parenthesis + + '''This is a state machine. Initial status is determined by the starting of the + expression. There are the following statuses: + + relation: this is the status if the expressions begins with something else than an + operator or a parenthesis. + binary operator: this is the status when parsing a binary operator, nothing much to say + unary operator: this status is more complex, since it will be followed by a parameter AND a + sub-expression. + sub-expression: this status is entered when finding a '(' and will be exited when finding a ')'. + means that the others open must be counted to determine which close is the right one.''' + + expression=expression.strip() + + if expression.startswith('('): #Parenthesis state + pass + elif expression.startswith("σ"): or expression.startswith("π") or expression.startswith("ρ"): #Unary + items.append(expression[0:2]) #Adding operator in the top of the list + + expression=expression[2:].strip() #Removing operator from the expression + par=expression.find('(') + + items.append(expression[:par]) #Inserting parameter of the operator + expression=expression[par:].strip() #Removing parameter from the expression + pass + elif expression.startswith("*") or expression.startswith("-") or expression.startswith("ᑎ") or expression.startswith("ᑌ"): #Binary short + pass + elif expression.startswith("ᐅ"): #Binary long + pass + else: + pass + + return items + + if __name__=="__main__": #n=node(u"((a ᑌ b) - c ᑌ d) - b") #n=node(u"((((((((((((2)))))))))))) - (3 * 5) - 2")