/*
Reorders the operands of the given operation in order to generate a "left handed" AST which performs evaluations
in natural order (from left to right).
341872
protected Expression reOrder(Expression left, Expression right, BinaryOperation.Op op) {
        if (right instanceof BinaryOperation) {
            BinaryOperation rightOp = (BinaryOperation) right;
            if (!rightOp.isSealed() && rightOp.getOp().getPriority() == op.getPriority()) {
                replaceLeft(rightOp, left, op);
                return right;
            }
        }
        return new BinaryOperation(op, left, right);
    }
956133
public static PredicateDef cmpEq(Expression left, Expression right) {
		return cmp(CompareOperation.EQ, left, right);
	}
608357
public static ExprDouble toExprDouble(Expression left, Expression right, int operation) {
	return new OpDouble(left, right, operation);
    }
137421
function binaryExpression(first, ops, rest) {
  if (associativity[ops[0]] === 'L') {
    const applyLeft = (x, y) => new BinaryExpression(x, ops.shift(), y);
    return [first].concat(rest).reduce(applyLeft);
  } else {
    const applyRight = (x, y) => new BinaryExpression(y, ops.pop(), x);
    return [first].concat(rest).reduceRight(applyRight);
  }
}
155903
function processOperators (ops) {
    if (!ops) return {};
    var operators = {};
    for (var i=0,k,prec;prec=ops[i]; i++) {
        for (k=1;k < prec.length;k++) {
            operators[prec[k]] = {precedence: i+1, assoc: prec[0]};
        }
    }
    return operators;
}
60000
public static function StackCalculus ($operand_left, $operator, $operand_right) {
		$operand_left	*= 1.0;
		$operand_right	*= 1.0;
		switch ($operator) {
			case '+':
				return $operand_left + $operand_right;
			case '-':
				return $operand_left - $operand_right;
			case '*':
				return $operand_left * $operand_right;
			case '/':
				if ($operand_right == 0) {
					return false;
				}
				return $operand_left / $operand_right;
			case '%':
				return $operand_left % $operand_right;
		}
	}
80275
public static Object and(Object left, Object right, EvaluationContext ctx) {
        Boolean l = EvalHelper.getBooleanOrNull( left );
        Boolean r = EvalHelper.getBooleanOrNull( right );
        // have to check for all nulls first to avoid NPE
        if ( (l == null && r == null) || (l == null && r == true) || (r == null && l == true) ) {
            return null;
        } else if ( l == null || r == null ) {
            return false;
        }
        return l && r;
    }
1173824
public static ExprBoolean toExprBoolean(Expression left, Expression right, int operation) {
	if (left instanceof Literal && right instanceof Literal) {
	    Boolean l = ((Literal) left).getBoolean(null);
	    Boolean r = ((Literal) right).getBoolean(null);

	    if (l != null && r != null) {
		switch (operation) {
		case Factory.OP_BOOL_AND:
		    return left.getFactory().createLitBoolean(l.booleanValue() && r.booleanValue(), left.getStart(), right.getEnd());
		case Factory.OP_BOOL_OR:
		    return left.getFactory().createLitBoolean(l.booleanValue() || r.booleanValue(), left.getStart(), right.getEnd());
		case Factory.OP_BOOL_XOR:
		    return left.getFactory().createLitBoolean(l.booleanValue() ^ r.booleanValue(), left.getStart(), right.getEnd());
		}
	    }
	}
	return new OpBool(left, right, operation);
    }
124896
@Pure /* not guaranteed, since compareTo() is invoked */
	@Inline("($1.compareTo($2))")
	public static <C> int operator_spaceship(Comparable<? super C> left, C right) {
		return left.compareTo(right);
	}
184565
private static void reverse(int first, int last, Swapper swapper) {
	// no more needed since manually inlined
	while (first < --last) {
		swapper.swap(first++,last);
	}
}
235202
def binary_operation_logical(self, rule, left, right, **kwargs):
        
        return self.evaluate_binop_logical(rule.operation, left, right, **kwargs)
748965
private void rotateTwiceOrdered() {
		Point2D_F64 a = ordered[0];
		Point2D_F64 b = ordered[1];
		Point2D_F64 c = ordered[2];
		Point2D_F64 d = ordered[3];

		ordered[0] = c;
		ordered[1] = d;
		ordered[2] = a;
		ordered[3] = b;
	}
407685
def preorder_iter_with_position(expression):
    
    yield expression, ()
    if isinstance(expression, Operation):
        for i, operand in enumerate(op_iter(expression)):
            for child, pos in preorder_iter_with_position(operand):
                yield child, (i, ) + pos
472382
function leftInorder(n, x) {
  if(n <= 0) {
    return 0
  }
  var r = rootInorder(n)
  if(x > r) {
    return leftInorder(n-r-1, x-r-1) + r + 1
  } else if(x === r) {
    return rootInorder(x)
  }
  return leftInorder(r, x)

}
948762
function B(iid, op, left, right, flags) {
        var bFlags = decodeBitPattern(flags, 3); // [isComputed, isOpAssign, isSwitchCaseComparison]
        var result, aret, skip = false;

        if (sandbox.analysis && sandbox.analysis.binaryPre) {
            aret = sandbox.analysis.binaryPre(iid, op, left, right, bFlags[1], bFlags[2], bFlags[0]);
            if (aret) {
                op = aret.op;
                left = aret.left;
                right = aret.right;
                skip = aret.skip;
            }
        }


        if (!skip) {
            switch (op) {
                case "+":
                    result = left + right;
                    break;
                case "-":
                    result = left - right;
                    break;
                case "*":
                    result = left * right;
                    break;
                case "/":
                    result = left / right;
                    break;
                case "%":
                    result = left % right;
                    break;
                case "<<":
                    result = left << right;
                    break;
                case ">>":
                    result = left >> right;
                    break;
                case ">>>":
                    result = left >>> right;
                    break;
                case "<":
                    result = left < right;
                    break;
                case ">":
                    result = left > right;
                    break;
                case "<=":
                    result = left <= right;
                    break;
                case ">=":
                    result = left >= right;
                    break;
                case "==":
                    result = left == right;
                    break;
                case "!=":
                    result = left != right;
                    break;
                case "===":
                    result = left === right;
                    break;
                case "!==":
                    result = left !== right;
                    break;
                case "&":
                    result = left & right;
                    break;
                case "|":
                    result = left | right;
                    break;
                case "^":
                    result = left ^ right;
                    break;
                case "delete":
                    result = delete left[right];
                    break;
                case "instanceof":
                    result = left instanceof right;
                    break;
                case "in":
                    result = left in right;
                    break;
                default:
                    throw new Error(op + " at " + iid + " not found");
                    break;
            }
        }

        if (sandbox.analysis && sandbox.analysis.binary) {
            aret = sandbox.analysis.binary(iid, op, left, right, result, bFlags[1], bFlags[2], bFlags[0]);
            if (aret) {
                result = aret.result;
            }
        }
        return (lastComputedValue = result);
    }
1129229
def evaluate_binop_logical(self, operation, left, right, **kwargs):
        
        if not operation in self.binops_logical:
            raise ValueError("Invalid logical binary operation '{}'".format(operation))
        result = self.binops_logical[operation](left, right)
        return bool(result)
1071481
def _calculate_operation_math(self, rule, left, right):
        

        # Attempt to keep integer data type for the result, when possible.
        if isinstance(left, IntegerRule) and isinstance(right, IntegerRule):
            result = self.evaluate_binop_math(rule.operation, left.value, right.value)
            if isinstance(result, list):
                return ListRule([IntegerRule(r) for r in result])
            return IntegerRule(result)

        # Otherwise the result is float.
        if isinstance(left, NumberRule) and isinstance(right, NumberRule):
            result = self.evaluate_binop_math(rule.operation, left.value, right.value)
            if isinstance(result, list):
                return ListRule([FloatRule(r) for r in result])
            return FloatRule(result)

        # This point should never be reached.
        raise Exception()