classConflictResolver
final class ConflictResolver
Settles the conflicts of one state the way its generator would.
A shift/reduce conflict is decided by precedence when both the token and the rule are ranked: the higher rank wins, and equal ranks follow the token's associativity. Without ranks the shift wins and the conflict is counted. A reduce/reduce conflict goes to the earlier rule, except that Lemon lets a higher-ranked rule win first.
Methods§
public function __construct(private Grammar $grammar)Parameters
$grammar | Grammar | Grammar whose precedences decide |
public function resolve(
array<int, int> $shifts,
array<int, array<int, int>> $lookaheads,
): ResolvedStateResolves the actions of one state.
Parameters
$shifts | array<int, int> | Target state by terminal |
$lookaheads | array<int, array<int, int>> | Lookahead bitset by completed rule |
Returns
ResolvedState The settled actionsTest cases 4
ConflictResolverTest::testResolveCountsAnUnrankedShiftReduceConflictAndShiftscallsConflictResolverTest::testResolveCountsAReduceReduceConflictAndKeepsTheEarlierRulecallsConflictResolverTest::testResolveKeepsPlainShiftsAndReductionscallsConflictResolverTest::testResolveLetsAHigherRankedLaterRuleWinUnderLemonsPolicycalls
Called from 1
Calls 11
- static-call ActionCode::shift() line 45
- function-call
ksortline 50 - static-call Bitset::members() line 53
- static-call ActionCode::reduce() line 56
- static-call ActionCode::isShift() line 58
- method-call ConflictResolver::shiftOrReduce() line 59
- class-const ActionCode::ERROR() line 62
- static-call ActionCode::isReduce() line 64
- method-call ConflictResolver::reduceOrReduce() line 69
- static-call ActionCode::rule() line 69
- new ResolvedState line 81
public function shiftOrReduce(int $terminal, int $rule): int|nullDecides a shift/reduce conflict on one terminal.
Parameters
$terminal | int | Terminal that can be shifted |
$rule | int | Rule that can be reduced |
Returns
int|null The winning action code, the error code when neither may win, or null when the conflict stays unresolvedTest cases 2
Called from 1
Calls 9
- method-call Grammar::memberPrecedence() line 94
- method-call Grammar::rulePrecedence() line 95
- static-call ActionCode::shift() line 100
- static-call ActionCode::reduce() line 100
- class-const Associativity::Right() line 104
- class-const Associativity::Left() line 105
- class-const Associativity::NonAssoc() line 106
- class-const ActionCode::ERROR() line 106
- class-const Associativity::Precedence() line 107
public function reduceOrReduce(int $earlier, int $later): int|nullDecides a reduce/reduce conflict between two rules that reduce on the same terminal.
Bison always keeps the earlier rule and counts the conflict. Lemon lets the higher-ranked rule win outright and counts the conflict only when the ranks are missing or equal, in which case the earlier rule wins.
Parameters
$earlier | int | Rule that currently holds the terminal |
$later | int | Rule that also reduces on it |
Returns
int|null The winning rule, or null when the earlier rule wins only by defaultTest cases 1
Called from 1
Calls 2
- class-const PrecedencePolicy::FirstRankedTerminal() line 125
- method-call Grammar::rulePrecedence() line 128
Private surface 1§
Implementation details, listed for orientation only.
private Grammar $grammarTest cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
ConflictResolverTest::testReduceOrReducecallsConflictResolverTest::testResolveCountsAnUnrankedShiftReduceConflictAndShiftscallsConflictResolverTest::testResolveCountsAReduceReduceConflictAndKeepsTheEarlierRulecallsConflictResolverTest::testResolveKeepsPlainShiftsAndReductionscallsConflictResolverTest::testResolveLetsAHigherRankedLaterRuleWinUnderLemonsPolicycallsConflictResolverTest::testShiftOrReducecallsConflictResolverTest::testShiftOrReduceLeavesABareRankUnresolvedcalls
Other tests reaching this symbol 2
ParseTableBuilderTestcallsLrParserTestcalls