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

The LALR(1) parse table of one grammar.

Each state has explicit actions for some symbols and a default for the rest. Looking an action up follows Lemon's order so that both generators' tables read the same way: the token itself, then the token it falls back to, then the wildcard, then the state's default.

Properties§

public SymbolTable $symbols
public list<TableRule> $rules
public list<int> $defaults
public ActionRows $rows
public array<int, int> $fallbacks = []
public int|null $wildcard = null

Methods§

public function __construct(
    public SymbolTable $symbols,
    public list<TableRule> $rules,
    public list<int> $defaults,
    public ActionRows $rows,
    public array<int, int> $fallbacks = [],
    public int|null $wildcard = null,
)

Parameters

$symbolsSymbolTableEvery symbol, numbered as the rows refer to them
$ruleslist<TableRule>Every rule, the augmented start rule first
$defaultslist<int>Default action code of each state, or the error code
$rowsActionRowsExplicit actions of each state
$fallbacksarray<int, int>Terminal to retry with by the terminal that failed
$wildcardint|nullTerminal whose action applies to any other terminal without one
public function action(int $state, int $symbol): int

Answers the action a state takes on a symbol.

Parameters

$stateintState number
$symbolintTerminal or nonterminal number

Returns

int The action code, the error code when the state rejects the symbol
Test cases 2
Called from 2
Calls 3
public function expectedTerminals(int $state): list<int>

Answers the terminals a state has an action for, so an error can say what it expected.

Parameters

$stateintState number

Returns

list<int> Terminal numbers with a shift or reduce, in number order
Test cases 1
Called from 1
Calls 4
public function stateCount(): int

Answers how many states the table has.

Returns

int State count
Test cases 1
Called from 2
Calls 1

Test cases 15§

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

Dedicated tests 4
Other tests reaching this symbol 11

Relations§

Instantiated in 2
Method calls 5
Type declarations 10