final class ConflictResolver
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

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

$grammarGrammarGrammar whose precedences decide
public function resolve(
    array<int, int> $shifts,
    array<int, array<int, int>> $lookaheads,
): ResolvedState
public function shiftOrReduce(int $terminal, int $rule): int|null

Decides a shift/reduce conflict on one terminal.

Parameters

$terminalintTerminal that can be shifted
$ruleintRule that can be reduced

Returns

int|null The winning action code, the error code when neither may win, or null when the conflict stays unresolved
Test cases 2
Called from 1
Calls 9
public function reduceOrReduce(int $earlier, int $later): int|null

Decides 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

$earlierintRule that currently holds the terminal
$laterintRule that also reduces on it

Returns

int|null The winning rule, or null when the earlier rule wins only by default
Test cases 1
Called from 1
Calls 2

Private surface 1§

Implementation details, listed for orientation only.

private Grammar $grammar

Test cases 9§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 7
Other tests reaching this symbol 2

Relations§

Instantiated in 1
Method calls 1