classLookaheadSets
final class LookaheadSets
The LALR(1) lookahead of every reduction, by the method of DeRemer and Pennello.
Each nonterminal transition of the automaton is a node. Its direct reads are the terminals that can follow it at once; the reads relation adds what follows a nullable nonterminal after it; the includes relation adds what follows a rule that ends with it. The lookahead of a completed rule is the union over the transitions the rule was entered from.
Methods§
public function __construct(
Grammar $grammar,
Lr0Automaton $automaton,
NullableSet $nullable,
Digraph $digraph = new \SqlParser\Automaton\Digraph(),
)Computes the lookahead sets.
Parameters
$grammar | Grammar | Grammar the automaton was built from |
$automaton | Lr0Automaton | Its LR(0) automaton |
$nullable | NullableSet | Its nullable nonterminals |
$digraph | Digraph | Closes sets over the relations |
Calls 9
- new Digraph line 35
- function-call
array_keysline 42 - function-call
countline 44 - method-call LookaheadSets::reads() line 50
- method-call Digraph::close() line 51
- method-call Grammar::rulesOf() line 55
- method-call NullableSet::tailNullable() line 59
- static-call Bitset::empty() line 72
- static-call Bitset::union() line 74
public function reads(
Lr0Automaton $automaton,
array<int, array<int, int>> $nodes,
int $terminalCount,
NullableSet $nullable,
): array{array<int, array<int, int>>, array<int, list<int>>}Computes the direct reads of every nonterminal transition and the reads relation between them.
Parameters
$automaton | Lr0Automaton | The automaton |
$nodes | array<int, array<int, int>> | Transition number by state and nonterminal |
$terminalCount | int | How many terminals a read set may hold |
$nullable | NullableSet | Nonterminals that derive the empty string |
Returns
array{array<int, array<int, int>>, array<int, list<int>>} Direct reads of each transition, and the transitions each one reads through a nullable nonterminalTest cases 1
Called from 1
Calls 5
- static-call Bitset::empty() line 99
- function-call
array_keysline 100 - static-call Bitset::add() line 102
- method-call NullableSet::isNullable() line 103
- function-call
ksortline 110
public function of(int $state): array<int, array<int, int>>Answers the lookahead of every rule completed in a state.
Parameters
$state | int | State number |
Returns
array<int, array<int, int>> Bitset of terminals by rule indexTest cases 2
Called from 1
Private surface 1§
Implementation details, listed for orientation only.
private array<int, array<int, array<int, int>>> $lookaheadsTest cases 5§
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 2
ParseTableBuilderTestcallsLrParserTestcalls