FoldedSequenceExpr

public indirect enum FoldedSequenceExpr : Hashable, Sendable
extension FoldedSequenceExpr: Monotonic

A sequence of binary operations stored as a tree whose structure encodes the evaluation order.

Instances of this type are created during type checking for each SequenceExpr in the program once the precedence groups of its operators have been determined. A tree is created by calling append(operator:right:) to append an operator and its right operand to the sub-sequence represented by self.

  • The expression of an operator in the AST together with its precedence.

    See more

    Declaration

    Swift

    public struct Operator : Hashable, Sendable
  • The application of an infix operator to its left and right operands.

    Declaration

    Swift

    case infix(Operator, left: FoldedSequenceExpr, right: FoldedSequenceExpr)
  • A leaf node representing some expression.

    Declaration

    Swift

    case leaf(AnyExprID)
  • Mutates self so that it represents the expression evaluated by appending operator.expr and right to self.

    This method uses operator.precedence to determine whether the whole expression represented by self should become the LHS of the new operation, or if the operator must apply to a sub-expression of self.

    Roughly, assuming self represents a + b and + has a lower precedence than *:

    • self.append(+, c) results in a tree representing (a + b) + c
    • self.append(*, c) results in a tree representing a + (b * c)

    Declaration

    Swift

    public mutating func append(operator: Operator, right: AnyExprID)