Questions: Parser Conflict Resolution

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

In the dangling-else problem, a parser generator defaults to preferring shift over reduce when it encounters the conflict on the 'else' token. What parse tree does this default produce for `if a then if b then s1 else s2`?

AThe else binds to the outer if, because shifting extends the outer construct
BThe else binds to the nearest (inner) if, because shifting continues building the inner if-then-else
CA syntax error is reported, because the grammar is ambiguous
DBoth parse trees are generated and the programmer must choose
Question 2 Multiple Choice

A grammar has a reduce-reduce conflict. The developer adds '%left' declarations to suppress it and all parser tests pass. What risk has been introduced?

ANone — precedence declarations are designed to resolve all types of conflicts safely
BThe parser may silently produce incorrect parse trees, because precedence rules don't naturally model the semantics of reduce-reduce conflicts
CThe grammar becomes LALR(2) instead of LALR(1), requiring a more powerful parser
DCompilation will be slower because the parser must check precedence at every step
Question 3 True / False

Any conflict in an LALR grammar is evidence of a design error and should be eliminated by rewriting the grammar.

TTrue
FFalse
Question 4 True / False

A reduce-reduce conflict is generally more dangerous than a shift-reduce conflict and should rarely be suppressed with precedence declarations.

TTrue
FFalse
Question 5 Short Answer

Why is a reduce-reduce conflict generally more concerning than a shift-reduce conflict, and what should a grammar designer do when they encounter one?

Think about your answer, then reveal below.