Practice free →
HomeGATE CSEcomputerscienceCompiler Design › A PARSER converts a stream of tokens into

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