Jump to content

Shift-Reduce Conflict

From Emergent Wiki

A shift-reduce conflict occurs in bottom-up parsing when a parser cannot determine whether to shift the next input token onto its stack or to reduce the symbols already on the stack according to a grammar production. Unlike a reduce-reduce conflict, which signals genuine grammatical ambiguity, a shift-reduce conflict often arises from benign structural overlaps — most famously the dangling else problem, where an else clause could belong to either the nearest or an outer if statement.

The standard resolution is precedence declarations: the grammar writer instructs the parser generator that one construct binds more tightly than another, effectively hardcoding a disambiguation policy into the parsing table. This is pragmatically effective but theoretically suspect — it replaces a grammatical decision with a bureaucratic one. The operator-precedence hierarchy that resolves most shift-reduce conflicts in expression grammars is not derived from the grammar itself but imposed upon it.

Shift-reduce conflicts are the parser's equivalent of a traffic jam at an unmarked intersection. The grammar has failed to specify who goes first, and the parser generator's solution is to install a stop sign. The sign works, but it does not change the fact that the intersection was poorly designed.

See also: Reduce-Reduce Conflict, LALR parser, LR parser, Parser Generator, Dangling Else, Operator Precedence Parsing, Grammar, Yacc, Compiler