munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.43k stars 1.01k forks source link

Challenge 6.2 Answer: Precedence within the conditional operator #1082

Open vorou opened 1 year ago

vorou commented 1 year ago

I can't grasp this sentence from the answer:

The left operand has higher precedence than the others, and the middle operand has lower precedence than the condition expression itself.

More specifically:

The left operand has higher precedence than the others

What does precedence even mean when we're talking about operands? Does this simply say that when we're executing the code the left operand will be evaluated first? Or does this affect the parsing somehow?

the middle operand has lower precedence than the condition expression itself

Again, not sure what precedence means here. According to this:

The expression in the middle of the conditional operator (between ? and :) is parsed as if parenthesized: its precedence relative to ?: is ignored.

Which I interpret as meaning that the middle operand has the highest precedence, i.e. the opposite of what you say. Could you please elaborate on what precedence means in this case?

(Thanks for the book!)