操作符

precedencegroupTablePrecedence {

    associativity: left

    higherThan: LogicalConjunctionPrecedence

}

precedencegroupSectionPrecedence {

    associativity: left

    higherThan: TablePrecedence

}

infixoperator+++ : TablePrecedence

infixoperator<<< : SectionPrecedence

precedencegroup: 定义了一个操作符优先级别。操作符优先级的定义和类型声明有些相似,一个操作符比需要属于某个特定的优先级。

infix:表示要定义的是一个中位操作符,即前后都是输入.

prefix: 前置运算符.

postfix:后置运算符.

associativity :定义了结合律,即如果多个同类的操作符顺序出现的计算顺序。

higherThan: 运算的优先级,点积运算是优先于乘法运算的。

lowerThan:来指定优先级低于某个其他组。

分别声明关联性和优先级

associativity Multiplicative left

precedence Multiplicative>Additive

precedence Exponentiative>Multiplicative

precedence Multiplicative {

  associativity(left)

  precedence(> Additive)

  precedence(< Exponentiative)

}

precedence Multiplicative {

  associativity: left

  precedence: higherThan(Additive)

  precedence: lowerThan(Exponentiative)

}

precedence Multiplicative {

  associativity(left)

  higherThan(Additive)

  lowerThan(Exponentiative)

}

precedence Multiplicative {

  associativity: left,

  higherThan: Additive,

  lowerThan: Exponentiative

}

precedence Multiplicative {

  associativity left

  higherThan Additive

  lowerThan Exponentiative

}

precedence Multiplicative {

  associativity left

  > Additive

  < Exponentiative

}

precedence Multiplicative : associativity(left),

higherThan(Additive),

lowerThan(Exponentiative)


precedence Multiplicative : associativity left,

higherThan Additive, lowerThan Exponentiative

precedence Multiplicative > Additive,

< Exponentiative,

associativity left

precedence left Multiplicative > Additive,

< Exponentiative

precedence associativity(left) Multiplicative > Additive,

< Exponentiative

Swift 标准库中已经定义了一些常用的运算优先级组,比如加法优先级 (AdditionPrecedence) 和乘法优先级 (MultiplicationPrecedence) 等,你可以在这里找到完整的列表

Standard library changes

precedencegroupAssignmentPrecedence {

  assignment: true

  associativity: right

}

precedencegroupTernaryPrecedence {

  associativity: right

  higherThan: AssignmentPrecedence

}

precedencegroupDefaultPrecedence {

  higherThan: TernaryPrecedence

}

precedencegroupLogicalDisjunctionPrecedence {

  associativity: left

  higherThan: TernaryPrecedence

}

precedencegroupLogicalConjunctionPrecedence {

  associativity: left

  higherThan: LogicalDisjunctionPrecedence

}

precedencegroupComparisonPrecedence {

  higherThan: LogicalConjunctionPrecedence

}

precedencegroupNilCoalescingPrecedence {

  associativity: right

  higherThan: ComparisonPrecedence

}

precedencegroupCastingPrecedence {

  higherThan: NilCoalescingPrecedence

}

precedencegroupRangeFormationPrecedence {

  higherThan: CastingPrecedence

}

precedencegroupAdditionPrecedence {

  associativity: left

  higherThan: RangeFormationPrecedence

}

precedencegroupMultiplicationPrecedence {

  associativity: left

  higherThan: AdditionPrecedence

}

precedencegroupBitwiseShiftPrecedence {

  higherThan: MultiplicationPrecedence

}

postfix operator ++

postfix operator --

// postfix operator !

prefix operator ++

prefix operator --

prefix operator !

prefix operator ~

prefix operator +

prefix operator -

// infix operator = : AssignmentPrecedence

infixoperator*=  : AssignmentPrecedence

infixoperator/=  : AssignmentPrecedence

infixoperator%=  : AssignmentPrecedence

infixoperator+=  : AssignmentPrecedence

infixoperator-=  : AssignmentPrecedence

infixoperator<<= : AssignmentPrecedence

infixoperator>>= : AssignmentPrecedence

infixoperator&=  : AssignmentPrecedence

infixoperator^=  : AssignmentPrecedence

infixoperator|=  : AssignmentPrecedence

// infix operator ?: : TernaryPrecedence

infixoperator||  : LogicalDisjunctionPrecedence

infixoperator&&  : LogicalConjunctionPrecedence

infixoperator<  : ComparisonPrecedence

infixoperator<=  : ComparisonPrecedence

infixoperator>  : ComparisonPrecedence

infixoperator>=  : ComparisonPrecedence

infixoperator==  : ComparisonPrecedence

infixoperator!=  : ComparisonPrecedence

infixoperator=== : ComparisonPrecedence

infixoperator!== : ComparisonPrecedence

infixoperator~=  : ComparisonPrecedence

infixoperator??  : NilCoalescingPrecedence

// infix operator as : CastingPrecedence

// infix operator as? : CastingPrecedence

// infix operator as! : CastingPrecedence

// infix operator is : CastingPrecedence

infixoperator..< : RangeFormationPrecedence

infixoperator... : RangeFormationPrecedence

infixoperator+  : AdditionPrecedence

infixoperator-  : AdditionPrecedence

infixoperator&+  : AdditionPrecedence

infixoperator&-  : AdditionPrecedence

infixoperator|  : AdditionPrecedence

infixoperator^  : AdditionPrecedence

infixoperator*  : MultiplicationPrecedence

infixoperator/  : MultiplicationPrecedence

infixoperator%  : MultiplicationPrecedence

infixoperator&*  : MultiplicationPrecedence

infixoperator&  : MultiplicationPrecedence

infixoperator<<  : BitwiseShiftPrecedence

infixoperator>>  : BitwiseShiftPrecedence

你可能感兴趣的:(操作符)