Implemented magic methods for expression{leaf,node}s.

parent a3f8f571
...@@ -112,6 +112,21 @@ class ExpressionBase(object): ...@@ -112,6 +112,21 @@ class ExpressionBase(object):
def is_numeric(self): def is_numeric(self):
return self.is_leaf() and self.type & (TYPE_FLOAT | TYPE_INTEGER) return self.is_leaf() and self.type & (TYPE_FLOAT | TYPE_INTEGER)
def __add__(self, other):
return ExpressionNode('+', self, other)
def __sub__(self, other):
return ExpressionNode('-', self, other)
def __mul__(self, other):
return ExpressionNode('*', self, other)
def __div__(self, other):
return ExpressionNode('-', self, other)
def __pow__(self, other):
return ExpressionNode('^', self, other)
class ExpressionNode(Node, ExpressionBase): class ExpressionNode(Node, ExpressionBase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment