I just stumbled upon the following pair of C ++ grammar rules:
conditional-expression: logical-or-expression logical-or-expression ? expression : assignment-expression ^^^^^^^^^^^^^^^^^^^^^ assignment-expression: conditional-expression ^^^^^^^^^^^^^^^^^^^^^^ unary-expression assignment-operator assignment-expression throw assignment-expression_opt
Note that the rules are mutually recursive: the conditional expression refers to the assignment-expression (rule 2), and the assignment expression refers to the conditional expression (rule 1).
What does this mean with regard to operator priority? Usually, a nonterminal for an operator with a stronger binding is found on the right side of the rules for an operator with a weaker binding, but not vice versa, right? Here's what puzzles me, in particular:
On the one hand, a = b ? c : d a = b ? c : d means a = (b ? c : d) , suggesting that ?: more strongly bound.
On the other hand, a ? b : c = d a ? b : c = d means a ? b : (c = d) a ? b : (c = d) , assuming that = more strongly bound.
Is the concept of operator precedence in the traditional sense simply not applicable here? Why?
c ++ operators syntax operator-precedence grammar
fredoverflow
source share