Parser
class Parser (View source)
Parser class.
Rules can be defined on the fly. Once finalized, a Parle\Lexer instance is required to deliver the token stream.
Constants
ACTION_ERROR |
|
ACTION_SHIFT |
|
ACTION_REDUCE |
|
ACTION_GOTO |
|
ACTION_ACCEPT |
|
ERROR_SYNTAX |
|
ERROR_NON_ASSOCIATIVE |
|
ERROR_UNKNOWN_TOKEN |
|
Properties
int | $action | ||
int | $reduceId |
Methods
Process next parser rule.
Finalize the grammar rules
Dump the current grammar to stdout.
Retrieve the error information in case Parle\Parser::action() returned the error action.
Declare a terminal with left associativity.
Declare a terminal, that cannot appear more than once in the row.
Declares a precedence rule for a fictitious terminal symbol.
Push a grammar rule.
Reset parser state using the given token id.
Declare a token with right-associativity
Retrieve a part of the match by a rule.
Declare a terminal to be used in the grammar.
Retrieve the id of the named token.
Retrieve the current parser operation description.
Details
void
advance()
Process next parser rule.
void
build()
Finalize the grammar rules
Any tokens and grammar rules previously added are finalized. The rule set becomes readonly and the parser is ready to start.
void
consume(string $data, Lexer $lexer)
Consume the data for parsing.
void
dump()
Dump the current grammar to stdout.
ErrorInfo
errorInfo()
Retrieve the error information in case Parle\Parser::action() returned the error action.
void
left(string $token)
Declare a terminal with left associativity.
void
nonassoc(string $token)
Declare a terminal, that cannot appear more than once in the row.
void
precedence(string $token)
Declares a precedence rule for a fictitious terminal symbol.
This rule can be later used in the specific grammar rules.
int
push(string $name, string $rule)
Push a grammar rule.
The production id returned can be used later in the parsing process to identify the rule matched.
void
reset(int $tokenId)
Reset parser state using the given token id.
void
right(string $token)
Declare a token with right-associativity
string
sigil(int $idx)
Retrieve a part of the match by a rule.
This method is equivalent to the pseudo variable functionality in Bison.
void
token(string $token)
Declare a terminal to be used in the grammar.
int
tokenId(string $token)
Retrieve the id of the named token.
string
trace()
Retrieve the current parser operation description.
This can be especially useful for studying the parser and to optimize the grammar.
bool
validate(string $data, Lexer $lexer)
Validate an input string.
The string is parsed internally, thus this method is useful for the quick input validation.