Which one of the following statements is TRUE?
2022
Which one of the following statements is TRUE?
- A.
The LALR(1) parser for a grammar G cannot have reduce-reduce conflict if the LR(1) parser for G does not have reduce-reduce conflict.
- B.
Symbol table is accessed only during the lexical analysis phase.
- C.
Data flow analysis is necessary for run-time memory management.
- D.
LR(1) parsing is sufficient for deterministic context-free languages.
Attempted by 83 students.
Show answer & explanation
Correct answer: D
Answer: LR(1) parsing is sufficient for deterministic context-free languages.
Short explanations for each statement:
Statement: "The LALR(1) parser for a grammar G cannot have reduce-reduce conflict if the LR(1) parser for G does not have reduce-reduce conflict." — Incorrect. LALR(1) merges LR(1) states with identical cores and that merging can introduce reduce-reduce or shift-reduce conflicts that were not present in the canonical LR(1) table.
Statement: "Symbol table is accessed only during the lexical analysis phase." — Incorrect. The symbol table is populated by the lexer but is accessed during parsing, semantic analysis, optimization, and code generation for resolving identifiers, types, scopes, and storage information.
Statement: "Data flow analysis is necessary for run-time memory management." — Incorrect. Data flow analysis is a compile-time technique used for optimizations and correctness checks. Run-time memory management (like garbage collection) operates at runtime and does not require data flow analysis to function, although compile-time analyses can help optimize memory usage.
Statement: "LR(1) parsing is sufficient for deterministic context-free languages." — Correct. Canonical LR(1) parsers use one-symbol lookahead to make deterministic shift/reduce decisions; LR(1) grammars correspond to deterministic context-free languages, so LR(1) parsing can handle those languages.
Key takeaway: LALR(1) may introduce conflicts by merging LR(1) states; the symbol table and analyses serve multiple compiler phases; and LR(1) parsing provides the determinism needed for deterministic context-free languages.
A video solution is available for this question — log in and enroll to watch it.