Next: Sequence methods, Previous: Symbol methods, Up: Grammar methods [Contents][Index]
Return value: On success, the numerically largest rule ID of g. On hard failure, -2.
A rule is accessible if it can be reached from the start symbol. A rule is accessible if and only if its LHS symbol is accessible. The start rule is always an accessible rule.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist. A common hard failure is calling this method with a grammar that is not precomputed.
Return value: On success 1 or 0: 1 if rule with ID rule_id is accessible, 0 if not. On soft failure, -1. On hard failure, -2.
A rule is nullable if it sometimes produces the empty string. A nulling rule is always a nullable rule, but not all nullable rules are nulling rules.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist. A common hard failure is calling this method with a grammar that is not precomputed.
Return value: On success 1 or 0: 1 if the rule with ID rule_id is nullable, 0 if not. On soft failure, -1. On hard failure, -2.
A rule is nulling if it always produces the empty string.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist. A common hard failure is calling this method with a grammar that is not precomputed.
Return value: On success 1 or 0: 1 if the rule with ID rule_id is nulling, 0 if not. On soft failure, -1. On hard failure, -2.
A rule is a loop rule if it non-trivially produces the string of length one that consists only of its LHS symbol. Such a derivation takes the parse back to where it started, hence the term “loop”. “Non-trivially” means the zero-step derivation does not count — the derivation must have at least one step.
The presence of a loop rule makes a grammar infinitely ambiguous, and applications will typically want to treat them as fatal errors. But nothing forces an application to do this, and Marpa will successfully parse and evaluate grammars with loop rules.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist. A common hard failure is calling this method with a grammar that is not precomputed.
Return value: On success 1 or 0: 1 if the rule with ID rule_id is a loop rule, 0 if not. On soft failure, -1. On hard failure, -2.
A rule is productive if it can produce a string of terminals. A rule is productive if and only if all the symbols on its RHS are productive. The empty string counts as a string of terminals, so that a nullable rule is always a productive rule. For that same reason, an empty rule is considered productive.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist. A common hard failure is calling this method with a grammar that is not precomputed.
Return value: On success 1 or 0: 1 if the rule with ID rule_id is productive, 0 if not. On soft failure, -1. On hard failure, -2.
The length of a rule is the number of symbols on its RHS.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist.
Return value: On success, the length of the rule with ID rule_id. On soft failure, -1. On hard failure, -2.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist.
Return value: On success, the ID of the LHS symbol of the rule with ID rule_id. On soft failure, -1. On hard failure, -2.
On success, creates a new external BNF rule in grammar g.
In addition to BNF rules, Marpa also allows sequence rules,
which are created by
the
marpa_g_sequence_new()
method.
See marpa_g_sequence_new().
We call
marpa_g_rule_new()
and
marpa_g_sequence_new()
rule creation methods.
Sequence rules and BNF rules are both rules: They share the same series of rule IDs, and are accessed and manipulated by the same methods, with the only differences being as noted in the descriptions of those methods.
Each grammar’s rule ID’s are a consecutive sequence of non-negative integers, starting at 0. This is intended to make it convenient for applications to store additional information about a grammar’s rules in an array. Within each grammar, the following is true:
n-1
.
The LHS symbol is lhs_id, and there are length symbols on the RHS. The RHS symbols are in an array pointed to by rhs_ids.
Possible hard failures, with their error codes, include:
MARPA_ERR_SEQUENCE_LHS_NOT_UNIQUE
: The LHS symbol is the same
as that of a sequence rule.
MARPA_ERR_DUPLICATE_RULE
: The new rule would duplicate another BNF
rule.
Another BNF rule is considered the duplicate of the new one,
if its LHS symbol is the same as symbol lhs_id,
if its length is the same as length,
and if its RHS symbols match one for one those
in the array of symbols rhs_ids.
Return value: On success, the ID of the new external rule. On hard failure, -2.
When successful, returns the ID of the symbol at index ix in the RHS of the rule with ID rule_id. The indexing of RHS symbols is zero-based.
Soft fails if rule_id is well-formed (a non-negative integer), but a rule with that ID does not exist.
A common hard failure is for ix not to be a valid index of the RHS. This happens if ix is less than zero, or or if ix is greater than or equal to the length of the rule.
Return value: On success, a symbol ID, which is always non-negative. On soft failure, -1. On hard failure, -2.
Next: Sequence methods, Previous: Symbol methods, Up: Grammar methods [Contents][Index]