From 4299b9bcf997cd7e115315f1eec51debfcfd8d5b Mon Sep 17 00:00:00 2001 From: EL MEHDI NHD <123629444+mido-dev1@users.noreply.github.com> Date: Thu, 11 Sep 2025 23:32:55 +0100 Subject: [PATCH] Fix Markdown typo + Fix the answer of question 3. Fix of the answer of question 3 is based on [https://en.cppreference.com/w/c/language/operator_precedence.html#cite_note-3](https://en.cppreference.com/w/c/language/operator_precedence.html#cite_note-3) ;) --- note/answers/chapter17_compiling.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/note/answers/chapter17_compiling.md b/note/answers/chapter17_compiling.md index bd0a7c7ae..7595c72a5 100644 --- a/note/answers/chapter17_compiling.md +++ b/note/answers/chapter17_compiling.md @@ -1,4 +1,4 @@ -##1 +## 1 It's: @@ -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.