classSymbolTable
final class SymbolTable
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
$terminals | list<string> | Terminal names, the end marker first |
$nonterminals | list<string> | Nonterminal names in declaration order |
Throws
GrammarException When the end marker is missing or a name repeatsCalls 2
- class-const SymbolTable::END() line 38
- new GrammarException line 39
public function id(string $name): int|nullAnswers the number of a symbol, or null when the name is unknown.
Parameters
$name | string | Symbol name as the grammar spells it |
Returns
int|null The symbol numberTest cases 1
SymbolTableTest::testIdcalls
public function name(int $id): stringAnswers the name of a symbol.
Parameters
$id | int | Symbol number |
Returns
string The name as the grammar spells itThrows
GrammarException When no symbol has that numberTest cases 3
Calls 2
- function-call
countline 74 - new GrammarException line 80
public function isTerminal(int $id): boolReports whether a number denotes a terminal.
Parameters
$id | int | Symbol number |
Returns
bool True for terminals, false for nonterminalsTest cases 1
Called from 3
- method-call SqlParser\Grammar\Grammar::rulePrecedence() packages/sql-parser/src/Grammar/Grammar.php:97
- method-call SqlParser\Lexer\TerminalIndex::token() packages/sql-parser/src/Lexer/TerminalIndex.php:65
- method-call SqlParser\Table\ParseTable::expectedTerminals() packages/sql-parser/src/Table/ParseTable.php:75
Calls 1
- function-call
countline 95
public function terminalCount(): intAnswers how many terminals there are, the end marker included.
Returns
int Terminal countTest cases 1
Called from 1
Calls 1
- function-call
countline 105
public function count(): intAnswers how many symbols there are in total.
Returns
int Terminal count plus nonterminal countTest cases 1
Calls 1
- function-call
countline 115
public function terminals(): list<string>Answers every terminal name in number order.
Returns
list<string> Terminal namesTest cases 1
public function nonterminals(): list<string>Answers every nonterminal name in number order.
Returns
list<string> Nonterminal namesTest cases 1
Private surface 3§
Implementation details, listed for orientation only.
private array<string, int> $idsprivate list<string> $terminalsprivate list<string> $nonterminalsTest cases 56§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 11
SymbolTableTest::testCountcallsSymbolTableTest::testIdcallsSymbolTableTest::testIsTerminalcallsSymbolTableTest::testNamecallsSymbolTableTest::testNameRejectsANegativeNumbercallsSymbolTableTest::testNameRejectsAnUnknownNumbercallsSymbolTableTest::testNamesMustBeUniquecallsSymbolTableTest::testNonterminalscallsSymbolTableTest::testTerminalCountcallsSymbolTableTest::testTerminalscallsSymbolTableTest::testTerminalsMustStartWithTheEndMarkercalls
Other tests reaching this symbol 45
BuildResultTest::testPropertiesAreKeptcallsClosureIndexTestcallsConflictResolverTest::testReduceOrReducecallsConflictResolverTest::testResolveCountsAnUnrankedShiftReduceConflictAndShiftscallsConflictResolverTest::testResolveCountsAReduceReduceConflictAndKeepsTheEarlierRulecallsConflictResolverTest::testResolveKeepsPlainShiftsAndReductionscallsConflictResolverTest::testResolveLetsAHigherRankedLaterRuleWinUnderLemonsPolicycallsConflictResolverTest::testShiftOrReducecallsConflictResolverTest::testShiftOrReduceLeavesABareRankUnresolvedcallsLookaheadSetsTestcallsLr0BuilderTestcallsNullableSetTestcallsParseTableBuilderTest::testExpandLookaheadscallsParseTableBuilderTest::testExpandShiftscallsBisonGrammarReaderTestcallsLemonGrammarReaderTestcallsGrammarBuilderTest::testIdcallsGrammarBuilderTest::testIdRejectsAnUnknownNamecallsGrammarBuilderTest::testNumberedRulescallsGrammarTest::testMemberPrecedenceLooksThroughATokenClasscallsGrammarTest::testPrecedenceOfcallsGrammarTest::testRulePrecedencePrefersTheNamedTerminalcallsGrammarTest::testRulePrecedenceTakesTheFirstRankedTerminalUnderLemonsPolicycallsGrammarTest::testRulePrecedenceTakesTheLastTerminalUnderBisonsPolicycallsGrammarTest::testRulesMustBeNumberedInOrdercallsGrammarTest::testRulesOfcallsGrammarTest::testStartSymbolcallsTerminalIndexTest::testTokencallsTerminalIndexTest::testTokenRejectsANonterminalNamecallsTerminalIndexTest::testTokenRejectsAnUnknownTerminalcallsTerminalIndexTest::testTokenscallsTerminalIndexTest::testTokensGivesTheSkippedTextToTheTokenThatFollowsItcallsMySqlParserTestcallsLrParserTestcallsPostgreSqlParserTestcallsResourceWriterTest::testWriteTablecallsSqliteParserTestcallsParseTableTest::testActionFallsBackThenUsesTheWildcardThenTheDefaultcallsParseTableTest::testActionPrefersTheExplicitEntrycallsParseTableTest::testExpectedTerminalscallsParseTableTest::testStateCountcallsTableCodecTest::testDecodeKeepsAMissingWildcardcallsTableCodecTest::testEncodeAndDecodeRoundTripcallsTableFileTest::testForgetcallsTableFileTest::testSaveAndLoadRoundTripcalls
Relations§
Instantiated in 2
Method calls 6
- method-call SqlParser\Grammar\Grammar::rulePrecedence() packages/sql-parser/src/Grammar/Grammar.php:97
- method-call SqlParser\Grammar\GrammarBuilder::id() packages/sql-parser/src/Grammar/GrammarBuilder.php:326
- method-call SqlParser\Lexer\TerminalIndex::token() packages/sql-parser/src/Lexer/TerminalIndex.php:64
- method-call SqlParser\Lexer\TerminalIndex::token() packages/sql-parser/src/Lexer/TerminalIndex.php:65
- method-call SqlParser\Table\ParseTable::action() packages/sql-parser/src/Table/ParseTable.php:57
- method-call SqlParser\Table\ParseTable::expectedTerminals() packages/sql-parser/src/Table/ParseTable.php:75
Constant reads 2
Type declarations 5
- type SqlParser\Grammar\Grammar packages/sql-parser/src/Grammar/Grammar.php:36
- type SqlParser\Grammar\GrammarBuilder packages/sql-parser/src/Grammar/GrammarBuilder.php:271
- type SqlParser\Grammar\GrammarBuilder packages/sql-parser/src/Grammar/GrammarBuilder.php:324
- type SqlParser\Lexer\TerminalIndex packages/sql-parser/src/Lexer/TerminalIndex.php:24
- type SqlParser\Table\ParseTable packages/sql-parser/src/Table/ParseTable.php:30