dd simplified method for Expression

This commit is contained in:
Lafrite 2014-12-19 15:40:35 +01:00
parent 450af74a0d
commit 5df17b4779

View File

@ -72,6 +72,12 @@ class Expression(object):
for s in self.child.simplify():
if old_s != s:
yield s
def simplified(self):
""" Get the simplified version of the expression """
if not self.can_go_further():
return self.postfix_tokens[0]
else:
return self.child.simplified()
def can_go_further(self):
"""Check whether it's a last step or not. If not create self.child the next expression.
@ -197,6 +203,8 @@ def test(exp):
for i in a.simplify():
print(i)
print(type(a.simplified()), ":", a.simplified())
print("\n")
if __name__ == '__main__':