In parser design, what does a shift-reduce conflict mean?
Think about the parser's choice between reading more input or applying a rule.
A shift-reduce conflict occurs when the parser must choose between shifting the next input symbol onto the stack or reducing the current symbols on the stack using a grammar rule. This ambiguity causes the parser to be unsure about the next action.
What best describes a reduce-reduce conflict in parsing?
Focus on the parser's choice between two reductions.
A reduce-reduce conflict happens when the parser has two different grammar rules that can both reduce the same symbols on the stack, making it unclear which rule to apply.
Given the grammar rules below, what type of parser conflict is most likely to occur?
S → a A d A → b A → b c
Consider what happens when the parser sees 'b' and then 'c' or 'd'.
The parser sees 'b' and must decide whether to shift 'c' (to match A → b c) or reduce A → b. This is a classic shift-reduce conflict.
Which statement correctly compares shift-reduce and reduce-reduce conflicts?
Think about the parser's decision points in each conflict type.
Shift-reduce conflicts happen when the parser must decide whether to shift or reduce next. Reduce-reduce conflicts happen when the parser must choose between two possible reductions. Both cause ambiguity but differ in the parser's choice.
A parser generator reports a shift-reduce conflict on the input string "id + id * id" with the grammar below:
E → E + E E → E * E E → id
Which approach correctly resolves this conflict to ensure multiplication has higher precedence than addition?
Think about how to represent operator precedence in grammar rules.
To resolve shift-reduce conflicts caused by operator precedence, the grammar should be rewritten to separate expressions by precedence levels. For example, defining separate rules for terms and factors ensures multiplication binds tighter than addition.
