Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

What are the common conflicts that can be encountered in shift-reduce parser ?

  1. Shift-Reduce Conflict:
    • What is it?: This happens when the parser isn’t sure whether to shift (move to the next input token) or reduce (apply a grammar rule) based on the current state and input.
    • Why does it happen?: Often occurs in recursive grammar where the parser can’t determine when one rule ends and another begins, leading to ambiguity.
    • Example: Imagine a rule like “if-else”. When the parser sees “if”, it might be unsure whether to wait for the “else” or to proceed with what’s next. This indecision causes the conflict.
  2. Reduce-Reduce Conflict:
    • What is it?: This occurs when the parser encounters a point where it can apply two or more grammar rules, but it’s uncertain which one to choose.
    • Why does it happen?: It usually arises when different rules lead to the same state, causing ambiguity about which rule to follow.
    • Example: Consider a grammar where both “if-else” and “if-elseif” are allowed. If the parser encounters an “if” followed by conditions for both “else” and “elseif”, it might not know which rule to apply, leading to the conflict.

Leave a Comment