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

What the closure of an item set adds, precomputed per nonterminal.

Closing an item set adds every rule of every nonterminal reachable from a nonterminal after a dot. Those additions depend only on the nonterminal, so they are computed once: the items that begin with each symbol, and the empty rules, which complete immediately.

Properties§

public int $itemWidth

Items encode a rule and a dot position as rule times this width plus dot.

Methods§

public function __construct(Grammar $grammar)

Precomputes the closure additions of every nonterminal.

Parameters

$grammarGrammarGrammar to index
Calls 3
public function reachable(Grammar $grammar, int $nonterminal): list<int>

Answers the nonterminals whose rules the closure of a nonterminal adds.

Parameters

$grammarGrammarGrammar to walk
$nonterminalintNonterminal after the dot

Returns

list<int> The nonterminal itself and every one reachable through a leading nonterminal
Test cases 1
Called from 1
Calls 3
public function startsWith(int $nonterminal): array<int, list<int>>

Answers the closure items that begin with each symbol, dot advanced past it.

Parameters

$nonterminalintNonterminal after the dot

Returns

array<int, list<int>> Items by their first symbol
Test cases 1
Called from 1
public function emptyRules(int $nonterminal): list<int>

Answers the empty rules the closure of a nonterminal completes at once.

Parameters

$nonterminalintNonterminal after the dot

Returns

list<int> Rule indexes
Test cases 1
Called from 1

Private surface 2§

Implementation details, listed for orientation only.

private array<int, array<int, list<int>>> $startsWith
private array<int, list<int>> $emptyRules

Test cases 7§

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

Dedicated tests 3
Other tests reaching this symbol 4

Relations§

Instantiated in 1
Method calls 2