A PARSER converts a stream of tokens into
Aa sequence of machine instructions
Ban Abstract Syntax Tree (AST)
Ca control-flow graph
Da symbol table
Answer & Solution
Correct answer: B. an Abstract Syntax Tree (AST)
1. The parser's job: take a flat sequence of tokens and recover the HIERARCHICAL TREE STRUCTURE that the language grammar describes.
2. Output: an ABSTRACT SYNTAX TREE (AST) — each interior node represents a syntactic construct (expression, statement, declaration), each leaf is a token.
3. Example: tokens `1 + 2 * 3` parse into the tree `(+ 1 (* 2 3))` reflecting precedence.
4. Machine instructions (option A) come from code generation (later phase). Control-flow graphs (C) from analysis. Symbol tables (D) from semantic analysis.
_Source: Bob Nystrom, "Crafting Interpreters", Ch 6 (Parsing Expressions — intro)._
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