Expression handle ":" but can't simplify with it yet

This commit is contained in:
lafrite 2014-01-19 18:38:15 +01:00
parent a0dbef2946
commit c88569b347

View File

@ -10,7 +10,7 @@ from formal import FormalExp
class Expression(object): class Expression(object):
"""A calculus expression. Today it can andle only expression with numbers later it will be able to manipulate unknown""" """A calculus expression. Today it can andle only expression with numbers later it will be able to manipulate unknown"""
PRIORITY = {"*" : 3, "/": 3, "+": 2, "-":2, "(": 1} PRIORITY = {"*" : 3, "/": 3, ":": 3, "+": 2, "-":2, "(": 1}
def __init__(self, exp): def __init__(self, exp):
""" Initiate the expression """ Initiate the expression
@ -135,7 +135,7 @@ class Expression(object):
# Special case for "-" at the begining of an expression or before "(" # Special case for "-" at the begining of an expression or before "("
elif tokens[-1] == "-" and \ elif tokens[-1] == "-" and \
str(tokens[-2]) in " (+-*/": str(tokens[-2]) in " (+-*/:":
tokens[-1] = - int(character) tokens[-1] = - int(character)
else: else:
tokens.append(int(character)) tokens.append(int(character))
@ -156,7 +156,7 @@ class Expression(object):
else: else:
tokens.append(FormalExp(letter = character)) tokens.append(FormalExp(letter = character))
elif character in "+-*/)": elif character in "+-*/):":
tokens.append(character) tokens.append(character)
elif character in "(": elif character in "(":
@ -329,13 +329,13 @@ class Expression(object):
@staticmethod @staticmethod
def isOperator(exp): def isOperator(exp):
"""Check if the expression is an opération in "+-*/" """Check if the expression is an opération in "+-*/:"
:param exp: an expression :param exp: an expression
:returns: boolean :returns: boolean
""" """
return (type(exp) == str and exp in "+-*/") return (type(exp) == str and exp in "+-*/:")
def test(exp): def test(exp):
@ -393,10 +393,10 @@ if __name__ == '__main__':
exp="-2*4(12 + 1)(3-12)" exp="-2*4(12 + 1)(3-12)"
test(exp) test(exp)
exp="-2+a+(12 + 1)(3-12) + 34a" exp="-2+a+(12 + 1)(3-12) : 34a"
test(exp) #test(exp)
e = Expression(exp) e = Expression(exp)
print(e) print(e.render(render = tex_render))
#exp="-2*b+a(12 + 1)(3-12)" #exp="-2*b+a(12 + 1)(3-12)"
#test(exp) #test(exp)