dd simplified method for Expression
This commit is contained in:
parent
450af74a0d
commit
5df17b4779
@ -72,6 +72,12 @@ class Expression(object):
|
|||||||
for s in self.child.simplify():
|
for s in self.child.simplify():
|
||||||
if old_s != s:
|
if old_s != s:
|
||||||
yield 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):
|
def can_go_further(self):
|
||||||
"""Check whether it's a last step or not. If not create self.child the next expression.
|
"""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():
|
for i in a.simplify():
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
|
print(type(a.simplified()), ":", a.simplified())
|
||||||
|
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user