Home › GATE CSE › computerscience › Compiler Design › Which is a token (TYPE) emitted by a typical C-s…
Which is a token (TYPE) emitted by a typical C-style scanner?
ADECLARATION_NODE
BFUNCTION_CALL_EXPR
CLEFT_PAREN
DAST_ROOT
Answer & Solution
Correct answer: C. LEFT_PAREN
1. TOKENS are output by the SCANNER and are LEXICAL units like:
- LEFT_PAREN, RIGHT_PAREN, COMMA, SEMICOLON
- PLUS, MINUS, STAR, SLASH
- NUMBER, STRING, IDENTIFIER
- Reserved words: IF, WHILE, RETURN, etc.
2. AST nodes (DECLARATION_NODE, FUNCTION_CALL_EXPR, AST_ROOT) are produced by the PARSER, a later phase. They're NOT tokens.
3. The distinction matters: scanner deals with the syntax of CHARACTERS; parser deals with the syntax of TOKENS.
4. So LEFT_PAREN is the only token type among the choices.
_Source: Bob Nystrom, "Crafting Interpreters", Ch 4.2 (Token types for Lox)._
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