Associativity

public enum Associativity : String, Hashable, Codable

The associativity of an operator, which determines how operators of the same precedence are grouped in the absence of parentheses.

Consider the expression a ~ b ~ c: If the ~ operator is left-associative, then the expression is interpreted as (a ~ b) ~ c. If the ~ operator is right-associative, then the expression is interpreted as a ~ (b ~ c).

For example, the Swift subtraction operator (-) is left-associative, such that 5 - 7 - 2 evaluates to -4 ((5 - 7) - 2) rather than 0 (5 - (7 - 2)).

  • Left-associative (operations are grouped from the left).

    Declaration

    Swift

    case left
  • Right-associative (operations are grouped from the right).

    Declaration

    Swift

    case right

ExpressibleBySyntax

  • Creates an instance initialized with the given syntax node.

    Declaration

    Swift

    public init?(_ node: PrecedenceGroupAssociativitySyntax)