Skip to content

Commit

Permalink
Add precedence rules for assignment operators to the precedence diagram.
Browse files Browse the repository at this point in the history
Also indicate what can appear within parentheses.

This is intended to be a clarification, not a design change. Note that
while we previously described the operand of `++` or `--` as being
simply an expression, the operand can never be anything other than the
kinds of expression the diagram now shows due to the expression category
rules added in carbon-language#2006.

Fixes carbon-language#3079.
  • Loading branch information
zygoloid committed Aug 10, 2023
1 parent fc5a954 commit cf67a5b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions docs/design/expressions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ graph BT
complement["^x"]
click complement "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/bitwise.md"
incDec["++x;<br>--x;"]
click incDec "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/assignment.md"
unary((" "))
as["x as T"]
Expand Down Expand Up @@ -136,7 +139,12 @@ graph BT
if>"if x then y else z"]
click if "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/if.md"
expressionEnd["x;"]
insideParens["(...)"]
assignment["x = y;<br>x $= y;"]
click assignment "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/assignment.md"
expressionStatement["x;"]
top --> parens & braces & unqualifiedName
Expand All @@ -146,8 +154,7 @@ graph BT
memberAccess --> top
pointer --> memberAccess
negation --> pointer
complement --> pointer
negation & complement & incDec --> pointer
unary --> negation & complement
%% Use a longer arrow here to put `not` next to `and` and `or`.
not -------> memberAccess
Expand All @@ -157,7 +164,8 @@ graph BT
logicalOperand --> comparison & not
and & or --> logicalOperand
logicalExpression --> and & or
if & expressionEnd --> logicalExpression
if & expressionStatement --> logicalExpression
insideParens & assignment --> if
```

The diagram's attributes are:
Expand Down

0 comments on commit cf67a5b

Please sign in to comment.