allowing empty left leaf for operator of 1 arity
This commit is contained in:
parent
b885bb6b8f
commit
7d00d3342a
@ -48,10 +48,8 @@ class Tree(object):
|
|||||||
>>> t.right_value
|
>>> t.right_value
|
||||||
2
|
2
|
||||||
"""
|
"""
|
||||||
if node is None or \
|
if node is None or right_value is None:
|
||||||
left_value is None or \
|
raise TypeError("Tree can't have an empty node or an empty right leaf")
|
||||||
right_value is None:
|
|
||||||
raise TypeError("Tree can't have empty node or leaf")
|
|
||||||
|
|
||||||
self.node = node
|
self.node = node
|
||||||
|
|
||||||
@ -64,7 +62,7 @@ class Tree(object):
|
|||||||
|
|
||||||
:example:
|
:example:
|
||||||
|
|
||||||
>>> t = MutableTree.fromStr("2+3*4")
|
>>> t = MutableTree.fromStr("2+3*4")
|
||||||
>>> print(t)
|
>>> print(t)
|
||||||
+
|
+
|
||||||
> 2
|
> 2
|
||||||
@ -492,7 +490,7 @@ class MutableTree(Tree):
|
|||||||
try:
|
try:
|
||||||
ans.set_node(c)
|
ans.set_node(c)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if OPERATORS[c]["priority"] > OPERATORS[ans.node]["priority"]:
|
if OPERATORS[c]["precedence"] > OPERATORS[ans.node]["precedence"]:
|
||||||
ans.append_bot(c)
|
ans.append_bot(c)
|
||||||
else:
|
else:
|
||||||
ans.append_top(c)
|
ans.append_top(c)
|
||||||
|
Loading…
Reference in New Issue
Block a user