Practice free →
HomeGATE CSEcomputerscienceCompiler 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)._
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions