You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your solution for conditional (ternary) operator is:
staticvoidconditional()
{
// Compile the then branch.parsePrecedence(compiler, PREC_CONDITIONAL);
consume(compiler, TOKEN_COLON,
"Expect ':' after then branch of conditional operator.");
// Compile the else branch.parsePrecedence(compiler, PREC_ASSIGNMENT);
}
I believe it is wrong because (in C) assignment in conditional operator is allowed in the then branch but not the else branch, so the precedence of the statements should be swapped:
staticvoidconditional()
{
// Compile the then branch.parsePrecedence(compiler, PREC_ASSIGNMENT);
consume(compiler, TOKEN_COLON,
"Expect ':' after then branch of conditional operator.");
// Compile the else branch.parsePrecedence(compiler, PREC_CONDITIONAL);
}
And since the else branch allows any expression, it may be more clear to use expression (as in grouping)?
The text was updated successfully, but these errors were encountered:
Your solution for conditional (ternary) operator is:
I believe it is wrong because (in C) assignment in conditional operator is allowed in the then branch but not the else branch, so the precedence of the statements should be swapped:
And since the else branch allows any expression, it may be more clear to use
expression
(as ingrouping
)?The text was updated successfully, but these errors were encountered: