This error is caused by the conditional expression syntax, which
logical-OR-expression ? expression : conditional-expression
Therefore, the part after : should be able to parse b = 200 . However, conditional-expression cannot parse this, since an assignment expression has a lower priority - you need to put brackets around the assignment expression
a>=5 ? b=100 : (b=200);
But the fact that you need a bracket here does not mean that the expression is otherwise parsed as (a>=5 ? b=100 : b) = 200 , itβs just an internal compiler artifact that says left in the error message operand assignment. The C language has the following two rules for the syntax of an assignment expression, and a rule that matches
conditional_expression unary_expression '=' assignment_expression
This gets in the way of recursive parsers that simply call parseConditionalExpression and check what the token means. Therefore, some implementations of the C syntax do not give a syntax error here, but analyze it as if the grammar said conditional_expression '=' ... above, and later when checking the parsing tree, confirm that the left side is lvalue. For example, Clang source code says
And the GCC parser source code says
source share