Start learning →

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)._
Practise this question with Quill — GATE CSE →

Keep practising Compiler Design

Browse all Compiler Design questions for GATE CSE, or explore more Computer Science topics.

Start a Compiler Design lesson →
Related questions