mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add precedence rules for assignment operators to the precedence diagram. (#3083)
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.
This commit is contained in:
@@ -17,6 +17,7 @@ enum PrecedenceLevel : int8_t {
|
||||
// Terms.
|
||||
TermPrefix,
|
||||
// Numeric.
|
||||
IncrementDecrement,
|
||||
NumericPrefix,
|
||||
Modulo,
|
||||
Multiplicative,
|
||||
@@ -53,7 +54,8 @@ struct OperatorPriorityTable {
|
||||
// Start with a list of <higher precedence>, <lower precedence>
|
||||
// relationships.
|
||||
MarkHigherThan({Highest}, {TermPrefix, LogicalPrefix});
|
||||
MarkHigherThan({TermPrefix}, {NumericPrefix, BitwisePrefix});
|
||||
MarkHigherThan({TermPrefix},
|
||||
{NumericPrefix, BitwisePrefix, IncrementDecrement});
|
||||
MarkHigherThan({NumericPrefix, BitwisePrefix},
|
||||
{As, Multiplicative, Modulo, BitwiseAnd, BitwiseOr,
|
||||
BitwiseXor, BitShift});
|
||||
@@ -64,7 +66,7 @@ struct OperatorPriorityTable {
|
||||
MarkHigherThan({Relational, LogicalPrefix}, {LogicalAnd, LogicalOr});
|
||||
MarkHigherThan({LogicalAnd, LogicalOr}, {If});
|
||||
MarkHigherThan({If}, {Assignment});
|
||||
MarkHigherThan({Assignment}, {Lowest});
|
||||
MarkHigherThan({Assignment, IncrementDecrement}, {Lowest});
|
||||
|
||||
// Types are mostly a separate precedence graph.
|
||||
MarkHigherThan({Highest}, {TypePrefix});
|
||||
@@ -208,7 +210,7 @@ auto PrecedenceGroup::ForLeading(TokenKind kind)
|
||||
|
||||
case TokenKind::MinusMinus:
|
||||
case TokenKind::PlusPlus:
|
||||
return PrecedenceGroup(Assignment);
|
||||
return PrecedenceGroup(IncrementDecrement);
|
||||
|
||||
case TokenKind::Caret:
|
||||
return PrecedenceGroup(BitwisePrefix);
|
||||
|
||||
Reference in New Issue
Block a user