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

Drives a parse table over a token stream and builds the syntax tree.

This is the shift-reduce loop every LALR(1) parser runs. A shift pushes the token; a reduce pops the symbols of a rule and pushes a node for its nonterminal, unless the rule stands in for a mid-rule action, which leaves no node. Accepting yields the node of the grammar's start symbol, which takes over the trivia of the end marker the augmented start rule ends with, so the text after the last token of the stream belongs to the tree too.

Methods§

public function __construct(private ParseTable $table)

Parameters

$tableParseTableTable to drive
public function parse(list<Token> $tokens, string $source = ''): Node

Parses a token stream.

Parameters

$tokenslist<Token>Tokens ending with the end marker
$sourcestringThe SQL text, for error positions

Returns

Node The node of the start symbol

Throws

SyntaxException When a token is not allowed where it stands
Test cases 5
Called from 3
Calls 15
public function expected(int $state): list<string>

Names the terminals a state accepts, for an error message.

Parameters

$stateintState the parser was in

Returns

list<string> Terminal names
Test cases 1
Called from 1
Calls 2

Private surface 1§

Implementation details, listed for orientation only.

private ParseTable $table

Test cases 10§

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

Dedicated tests 6
Other tests reaching this symbol 4

Relations§

Instantiated in 3
Method calls 3