A language designer adds a new ternary operator to a programming language that uses a Bison-generated parser. What is the primary change required to the parser?
AModify the grammar specification file to include the new operator's productions and precedence, then regenerate the parser
BUpdate the LALR(1) action/goto tables by hand to add new rows for the operator's tokens
CRewrite the recursive descent functions that handle expression parsing
DUpdate the FIRST and FOLLOW sets manually and patch the parser source code directly
The core value of parser generators is maintainability: grammar changes require modifying the declarative specification file and regenerating — the tool handles table recomputation automatically. Options 2 and 4 describe what parser generators exist to avoid. Option 3 describes hand-written recursive descent, which is a different approach altogether.
Question 2 Multiple Choice
During parser generation, Bison reports a shift-reduce conflict. What does this indicate, and what are valid responses?
AThe grammar is ambiguous at that point; it can be resolved by rewriting the grammar, adding precedence declarations, or accepting Bison's default resolution
BThe grammar is syntactically incorrect and cannot produce a valid parser under any circumstances
CThe grammar is too complex for LALR parsing and must be converted to an LL grammar for ANTLR
DThe lexer is generating tokens in the wrong order, causing conflicts in the parsing table
A shift-reduce conflict means two valid actions are possible at some parser state: shift the next token onto the stack, or reduce the current stack contents using a production. This ambiguity in the grammar (not the lexer) must be resolved. Yacc/Bison accept precedence declarations as a common resolution mechanism; alternatively, the grammar can be rewritten to eliminate the ambiguity. The conflict is a design signal, not a fatal error.
Question 3 True / False
Bison and ANTLR both implement the same underlying parsing strategy (LALR), differing mainly in their target output language.
TTrue
FFalse
Answer: False
Bison generates LALR(1) parsers — bottom-up, LR-family parsers that shift tokens onto a stack and reduce when a complete right-hand side is recognized. ANTLR generates LL(*) parsers — top-down parsers that predict which production to apply using adaptive lookahead. They implement fundamentally different parsing strategies with different strengths, limitations, and conflict types (shift-reduce for LR; LL conflicts for top-down).
Question 4 True / False
A primary practical advantage of parser generators over hand-written recursive descent parsers is that generated parsers produce clearer, more informative syntax error messages.
TTrue
FFalse
Answer: False
This is the opposite of the truth. Generated parsers often produce opaque error messages that reference internal table states rather than meaningful grammar concepts. Hand-written recursive descent parsers excel at error reporting because the programmer can insert context-specific messages at every decision point and implement custom error recovery strategies. This is a major reason why major compilers (GCC, Clang, Rust) use hand-written parsers despite the existence of excellent generators.
Question 5 Short Answer
Why do some major production compilers use hand-written recursive descent parsers rather than parser generators, even though excellent tools like Bison and ANTLR exist?
Think about your answer, then reveal below.
Model answer: Hand-written parsers provide superior error reporting and recovery — when a syntax error occurs, the programmer can emit context-specific messages and gracefully continue parsing. They also allow fine-grained control over parsing decisions. Parser generators produce opaque output (errors reference table states) and customizing error recovery is difficult. The engineering tradeoff: generators win on development speed and grammar clarity; hand-written parsers win on user-facing quality and fine control.
This is not a theoretical question — GCC switched from Bison to a hand-written parser for exactly these reasons. Understanding the tradeoff helps engineers make the right choice: parser generators for most compilers courses and projects where grammar clarity and maintainability dominate; hand-written for production compilers where error messages are a key user-experience feature.