solve bug with expression like [2, op.sub1]
This commit is contained in:
parent
cd6e8c5ca3
commit
108c794a04
@ -58,6 +58,7 @@ class Expression(object):
|
|||||||
|
|
||||||
if len(expression.postfix_tokens) == 1:
|
if len(expression.postfix_tokens) == 1:
|
||||||
return expression.postfix_tokens[0]
|
return expression.postfix_tokens[0]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
expression._isExpression = 1
|
expression._isExpression = 1
|
||||||
return expression
|
return expression
|
||||||
@ -166,6 +167,20 @@ class Expression(object):
|
|||||||
tmpTokenList.append(tokenList[0])
|
tmpTokenList.append(tokenList[0])
|
||||||
|
|
||||||
del tokenList[0]
|
del tokenList[0]
|
||||||
|
|
||||||
|
if len(tokenList) == 2 and isNumber(tokenList[0]) \
|
||||||
|
and isOperator(tokenList[1]) and tokenList[1].arity == 1:
|
||||||
|
# S'il reste deux éléments dont un operation d'arité 1
|
||||||
|
op1 = tokenList[0]
|
||||||
|
operator = tokenList[1]
|
||||||
|
|
||||||
|
res = operator(op1)
|
||||||
|
|
||||||
|
tmpTokenList.append(res)
|
||||||
|
|
||||||
|
# Comme on vient de faire le calcul, on peut détruire aussi les deux prochains termes
|
||||||
|
del tokenList[0:2]
|
||||||
|
|
||||||
tmpTokenList += tokenList
|
tmpTokenList += tokenList
|
||||||
|
|
||||||
steps = expand_list(tmpTokenList)
|
steps = expand_list(tmpTokenList)
|
||||||
|
@ -399,7 +399,11 @@ def test(p,q):
|
|||||||
#print("\t", str(i.postfix))
|
#print("\t", str(i.postfix))
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
print("\n Evaluer ------")
|
print("\n Evaluer p ------")
|
||||||
|
for i in p(3).simplify():
|
||||||
|
print(i)
|
||||||
|
|
||||||
|
print("\n Evaluer q ------")
|
||||||
for i in q(3).simplify():
|
for i in q(3).simplify():
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user