Previous: Rank methods, Up: Grammar methods [Contents][Index]
On success, returns a boolean which is 1 iff
g has a cycle.
Cycles make a grammar infinitely ambiguous,
and are considered useless in current
practice.
Cycles make processing the grammar less
efficient, sometimes considerably so.
Applications will almost always want to treat cycles
as mistakes on the part of the writer of the grammar.
To determine which rules are in the cycle,
marpa_g_rule_is_loop()
can be used.
Return value: On success, a boolean. On hard failure, -2.
Return value: On success, a boolean which is 1 iff grammar g is precomputed. On hard failure, -2.
On success, and on fully recoverable hard failure, precomputes the grammar g. Precomputation involves running a series of grammar checks and “precomputing” some useful information which is kept internally to save repeated calculations. After precomputation, the grammar is “frozen” in many respects, and many grammar mutators that succeed before precomputation will cause hard failures after precomputation. Precomputation is necessary for a recognizer to be generated from a grammar.
When called, clears any events already in the event queue.
May return one or more events.
The types of event that this method may return
are
A MARPA_EVENT_LOOP_RULES
,
MARPA_EVENT_COUNTED_NULLABLE
,
MARPA_EVENT_NULLING_TERMINAL
.
All of these events occur only on failure.
Applications must be prepared for this method
to return additional events,
including events that occur on success.
Events may be queried using the
marpa_g_event()
method.
See marpa_g_event().
The fully recoverable hard failure is
MARPA_ERR_GRAMMAR_HAS_CYCLE
.
Recall that for fully recoverable hard failures
this method precomputes the grammar.
Most appplications, however, will want to treat
a grammar with cycles as if it were
a library-recoverable error.
A MARPA_ERR_GRAMMAR_HAS_CYCLE
error occurs
iff
a MARPA_EVENT_LOOP_RULES
event occurs.
For more details on cycles,
see marpa_g_has_cycle().
The error code MARPA_ERR_COUNTED_NULLABLE
is library-recoverable.
This failure occurs when a symbol on the RHS of a sequence rule is
nullable,
which Libmarpa does not allow in a grammar.
Error code MARPA_ERR_COUNTED_NULLABLE
occurs iff
one or more MARPA_EVENT_COUNTED_NULLABLE
events occur.
There is one MARPA_EVENT_COUNTED_NULLABLE
event for every symbol
that is a nullable on the right hand side of a sequence
rule.
An application may use these events to inform the user
of the problematic symbols,
and this detail may help the user fix the grammar.
The error code MARPA_ERR_NULLING_TERMINAL
occurs only if LHS terminals are enabled.
The LHS terminals feature is deprecated.
See LHS terminals.
Error code MARPA_ERR_NULLING_TERMINAL
is library-recoverable.
One or more MARPA_EVENT_NULLING_TERMINAL
events will occur iff
this method fails with error code MARPA_ERR_NULLING_TERMINAL
.
See Nulling terminals.
Among the other error codes that may case this method to fail are the following:
MARPA_ERR_NO_RULES
: The grammar has no rules.
MARPA_ERR_NO_START_SYMBOL
: No start symbol was specified.
MARPA_ERR_INVALID_START_SYMBOL
: A start symbol ID was specified, but it
is not the ID of a valid symbol.
MARPA_ERR_START_NOT_LHS
: The start symbol is not on the LHS of any rule.
MARPA_ERR_UNPRODUCTIVE_START
: The start symbol is not productive.
More details of these can be found under the description of the appropriate code. See External error codes.
Return value: On success, a non-negative number,
whose value is otherwise unspecified.
On hard failure, -2.
For the error code MARPA_ERR_GRAMMAR_HAS_CYCLE
,
the hard failure is fully recoverable.
For the error codes MARPA_ERR_COUNTED_NULLABLE
and MARPA_ERR_NULLING_TERMINAL
,
the hard failure is library-recoverable.
Previous: Rank methods, Up: Grammar methods [Contents][Index]