Home › GATE CSE › computerscience › Compiler Design › Scanning a comment like `// hello` in C-style la…
Scanning a comment like `// hello` in C-style languages typically results in
Aa COMMENT token emitted to the parser
Ban error: comments are not valid
Cthe comment is SKIPPED (consumed but emits no token)
Dthe parser handles comments
Answer & Solution
Correct answer: C. the comment is SKIPPED (consumed but emits no token)
1. Comments are TRIVIA for the parser — they carry no syntactic meaning.
2. The scanner CONSUMES the comment characters (so they don't appear in the token stream) and EMITS NO TOKEN.
3. Same treatment for WHITESPACE: consumed and skipped, no token emitted.
4. Exception: some tools (linters, documentation extractors, modern IDEs) preserve comments as trivia tokens attached to nearby code. But the parser ignores them.
5. Options A, B, D mischaracterise normal compiler behaviour.
_Source: Bob Nystrom, "Crafting Interpreters", Ch 4.6 (Comments — implicit skip)._
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