Преглед изворни кода

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

Sander Mathijs van Veen пре 14 година
родитељ
комит
22c543b68f
1 измењених фајлова са 15 додато и 0 уклоњено
  1. 15 0
      src/node.py

+ 15 - 0
src/node.py

@@ -112,6 +112,21 @@ class ExpressionBase(object):
     def is_numeric(self):
         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):
     def __init__(self, *args, **kwargs):