Skip to content

Exclude discarded lookaheads from reduce/reduce conflicts - #874

Merged
ydah merged 1 commit into
masterfrom
fix/report-selected-reduction-conflicts
Nov 14, 2026
Merged

ydah merged 1 commit into
masterfrom
fix/report-selected-reduction-conflicts

Conversation

@ydah

@ydah ydah commented Nov 14, 2026

Copy link
Copy Markdown
Member

compute_reduce_reduce_conflicts compares the original lookahead sets, including tokens removed during shift/reduce conflict resolution. This can report a reduce/reduce conflict between reductions that no longer compete, causing %expect 0 to reject the grammar.

Use selected_look_ahead when finding overlapping reduction lookaheads, following Bison's post-resolution conflict checks (https://github.com/akimd/bison/blob/v3.8.2/src/conflicts.c#L354-L364).

For example:

%expect 0
%precedence LOW
%precedence 'b'
%precedence HIGH
%%
start: 'a' empty 'b' 'x' | direct 'b' 'y'
     | 'a' 'b' 'z' | 'a' empty 'c';
empty: %empty %prec LOW;
direct: 'a' %prec HIGH;

The reduction by empty loses to the shift on 'b', and direct then removes that shift. Only direct remains on 'b', so there is no reduce/reduce conflict. Both LALR and IELR generation previously failed with reduce/reduce conflicts: 1 found, 0 expected. They now succeed, matching Bison 3.8.2.

States that become conflict-free can also use the existing default-reduction selection.

@ydah
ydah merged commit 4ba44b0 into master Nov 14, 2026
45 checks passed
@ydah
ydah deleted the fix/report-selected-reduction-conflicts branch November 14, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant