What is a SYNTAX ERROR?
Athe program produces wrong output
Bthe program uses an undefined variable
Ctokens do not form a valid sentence in the grammar
Dthe program is too slow
Answer & Solution
Correct answer: C. tokens do not form a valid sentence in the grammar
1. A SYNTAX ERROR is detected by the parser when the token sequence DOES NOT MATCH any rule in the grammar.
2. Example: `if (x ` (missing closing `)` and body) is a syntax error.
3. CONTRAST with SEMANTIC errors (type mismatch, undefined variable — option B) detected later.
4. CONTRAST with RUNTIME errors (division by zero, null pointer — option A's case for some).
5. Good parsers REPORT syntax errors with helpful context (line, column, expected vs found) AND TRY to RECOVER (continue parsing to find more errors).
_Source: Bob Nystrom, "Crafting Interpreters", Ch 6.3 (Syntax Errors)._
Related questions
The FOLLOW(A) set in LL parsing isThe FIRST(α) set of a string α in LL parsing isAfter the parser produces an AST, the next compiler phase is typicallyA SHIFT/REDUCE CONFLICT in an LR parser occurs whenWhich of these is a BOTTOM-UP (LR) parser feature?An LL(1) grammar requires that, given the leftmost non-terminal and ONE token of lookaheadLL parsers (recursive descent) parse from thePANIC MODE error recovery in a parser works by