# Exponentiation operator and precedence group

**URL:** <https://forums.swift.org/t/exponentiation-operator-and-precedence-group/44895>\
**Category:** Pitches\
**Created:** [February 19, 2021, 12:01am UTC](https://forums.swift.org/t/exponentiation-operator-and-precedence-group/44895 "2021-02-19T00:01:23Z")\
**Posts on this page:** 1\
**Showing post:** 45

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [February 23, 2021, 9:29pm UTC](https://forums.swift.org/t/exponentiation-operator-and-precedence-group/44895/45 "2021-02-23T21:29:40Z")

</div>

> [@Nevin](#):
>
> Postfix, then prefix, then infix in decreasing order of precedence, seems pretty straightforward to me.

If only it were that simple:

```cpp
  // E.g. 'fn() as Int << 2'.
  // In this case '<<' has higher precedence than 'as', but the LHS should
  // be 'fn() as Int' instead of 'Int'.

```

```cpp
  // If the left-hand-side is a 'try' or 'await', hoist it up turning
  // "(try x) + y" into try (x + y).

```

```cpp
  // If this is an assignment operator, and the left operand is an optional
  // evaluation, pull the operator into the chain.

```

```cpp
  // If the right operand is a try or await, it's an error unless the operator
  // is an assignment or conditional operator and there's nothing to
  // the right that didn't parse as part of the right operand.
  //
  // Generally, nothing to the right will fail to parse as part of the
  // right operand because there are no standard operators that have
  // lower precedence than assignment operators or the conditional
  // operator.
  //
  // We allow the right operand of the conditional operator to begin
  // with 'try' for consistency with the middle operand. This allows:
  // x ? try foo() : try bar()
  // but not:
  // x ? try foo() : try bar() $#! 1
  // assuming $#! is some crazy operator with lower precedence
  // than the conditional operator.

```

```swift
  // If the operator is a cast operator, the RHS can't extend past the type
  // that's part of the cast production.

```

---

_[View the full topic](https://forums.swift.org/t/exponentiation-operator-and-precedence-group/44895)._
