blob: 97208e5be574fcfac1cda6cecb7135038c0182ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
from .node import Node as _Node
class BinaryOperator(_Node):
"""BinaryOperators have at most two children."""
def __init__(self, leftchild=None, rightchild=None):
"""Create binary operator (possibly with children)."""
_Node.__init__(self)
self.children = [leftchild, rightchild]
@classmethod
def load(nodeclass, settings):
"""Creates a new BinaryOperator of type nodeclass.
Default BinaryOperators don't have any parameters,
so this just returns a new node.
"""
return nodeclass()
def get_equation_string(self, variable):
"""Returns a string representing the current equation."""
return "(%s %s %s)" % (
_Node.get_equation_string(self.children[0], variable),
self.operatorstring,
_Node.get_equation_string(self.children[1], variable))
|