Exemple #1
0
    def __str__(self):

        operand = self.operand.ref

        op_fixity = make_token(OPERATOR_FIXITIES, self)
        operand_fixity = make_token(OPERATOR_FIXITIES, operand)

        if operand_fixity.lbp and op_fixity > operand_fixity:
            operand_str = parenthesized
        else:
            operand_str = str

        return '{}{}'.format(self.name, operand_str(operand))
Exemple #2
0
    def __str__(self):

        left = self.left.ref
        right = self.right.ref

        op_fixity = make_token(OPERATOR_FIXITIES, self)
        left_fixity = make_token(OPERATOR_FIXITIES, left)
        right_fixity = make_token(OPERATOR_FIXITIES, right)

        if left_fixity.rbp and left_fixity < op_fixity:
            left_str = parenthesized
        else:
            left_str = str

        if right_fixity.lbp and op_fixity > right_fixity:
            right_str = parenthesized
        else:
            right_str = str

        return '{} {} {}'.format(left_str(left), self.name, right_str(right))