From cf67a5b37c5e62dfe8e88a55ecbb3963f4925b5d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 10 Aug 2023 11:19:15 -0700 Subject: [PATCH] Add precedence rules for assignment operators to the precedence diagram. 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 #2006. Fixes #3079. --- docs/design/expressions/README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/design/expressions/README.md b/docs/design/expressions/README.md index a6dccf90ea250..aa411906c558f 100644 --- a/docs/design/expressions/README.md +++ b/docs/design/expressions/README.md @@ -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;
--x;"] + click incDec "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/assignment.md" + unary((" ")) as["x as T"] @@ -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;
x $= y;"] + click assignment "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/assignment.md" + + expressionStatement["x;"] top --> parens & braces & unqualifiedName @@ -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 @@ -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: