def get_process_fragment(self): return Fragment([ self.token("result").r.eq( _Operator(self.op, [self.token("operands").a, self.token("operands").b])) ])
def optree(op, operands, lb=None, ub=None, default=None): if lb is None: lb = 0 if ub is None: ub = len(operands) l = ub - lb if l == 0: if default is None: raise AttributeError else: return default elif l == 1: return operands[lb] else: s = lb + l//2 return _Operator(op, [optree(op, operands, lb, s, default), optree(op, operands, s, ub, default)])
def optree(op, operands, lb=None, ub=None, default=None): if lb is None: lb = 0 if ub is None: ub = len(operands) l = ub - lb if l == 0: if default is None: raise AttributeError else: return default elif l == 1: return operands[lb] else: s = lb + l // 2 return _Operator(op, [ optree(op, operands, lb, s, default), optree(op, operands, s, ub, default) ])
def get_process_fragment(self): return Fragment([ self.token("result").r.eq(_Operator(self.op, [self.token("operands").a, self.token("operands").b])) ])
def visit_Operator(self, node): return _Operator(node.op, [self.visit(o) for o in node.operands])