Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions note/answers/chapter17_compiling.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
##1
## 1

It's:

Expand Down Expand Up @@ -51,19 +51,19 @@ The `?:` operator has lower precedence than almost anything, so we add a new `PR
static void conditional()
{
// Compile the then branch.
parsePrecedence(compiler, PREC_CONDITIONAL);
parsePrecedence(compiler, PREC_ASSIGNMENT);

consume(compiler, TOKEN_COLON,
"Expect ':' after then branch of conditional operator.");

// Compile the else branch.
parsePrecedence(compiler, PREC_ASSIGNMENT);
parsePrecedence(compiler, PREC_CONDITIONAL);
}
```

Of course a full implementation needs more code to actually do the conditional
evaluation, but that should compile the operands with the right precedence. Note
that the precedence of the operands is a little unusual. The precedence of the
last operand is *lower* than the conditional expression itself.
middle operand is *lower* than the conditional expression itself.

That might be surprising, but it's how C rolls.