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

Numbers every symbol of a grammar, terminals first.

Terminal identifiers run from zero, with the end marker at zero, and the nonterminals continue after the last terminal. The automaton and the parse table refer to symbols by these numbers only.

Constants§

public const END = '$end'

The name of the terminal that marks the end of the input.

Methods§

public function __construct(private list<string> $terminals, private list<string> $nonterminals)

Parameters

$terminalslist<string>Terminal names, the end marker first
$nonterminalslist<string>Nonterminal names in declaration order

Throws

GrammarException When the end marker is missing or a name repeats
Calls 2
public function id(string $name): int|null

Answers the number of a symbol, or null when the name is unknown.

Parameters

$namestringSymbol name as the grammar spells it

Returns

int|null The symbol number
Test cases 1
Called from 2
public function name(int $id): string

Answers the name of a symbol.

Parameters

$idintSymbol number

Returns

string The name as the grammar spells it

Throws

GrammarException When no symbol has that number
Test cases 3
Calls 2
public function isTerminal(int $id): bool

Reports whether a number denotes a terminal.

Parameters

$idintSymbol number

Returns

bool True for terminals, false for nonterminals
Test cases 1
Called from 3
Calls 1
public function terminalCount(): int

Answers how many terminals there are, the end marker included.

Returns

int Terminal count
Test cases 1
Called from 1
Calls 1
public function count(): int

Answers how many symbols there are in total.

Returns

int Terminal count plus nonterminal count
Test cases 1
Calls 1
public function terminals(): list<string>

Answers every terminal name in number order.

Returns

list<string> Terminal names
Test cases 1
public function nonterminals(): list<string>

Answers every nonterminal name in number order.

Returns

list<string> Nonterminal names
Test cases 1

Private surface 3§

Implementation details, listed for orientation only.

private array<string, int> $ids
private list<string> $terminals
private list<string> $nonterminals

Test cases 56§

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

Dedicated tests 11
Other tests reaching this symbol 45

Relations§

Instantiated in 2
Method calls 6
Constant reads 2
Type declarations 5