8. Procedures

Formal grammars may be seen as declarative descriptions of string languages. A frequently raised question addresses the possibility of encapsulating procedural knowledge into declarative knowledge. In a formal grammar this may be accomplished by "flags" (see "Programmed grammars", QuickStart §11) or by other procedures, see for instance "Destroying structures" §4.5.

Here we deal with procedures that may be inserted in subgrammar rules. Every procedure name starts with an underline character. Current procedures are

_destru _goto _failed _repeat _stop
that control derivations, and

_print _printOn _printOff _stepOn _stepOff _traceOn _traceOff
that modify the trace output, not the derivation itself.

Note that the names of procedures are not case-sensitive. Thus, for example, "_traceOn" may be equivalently written "_Traceon", "_TRACEON", etc.

If a procedure appears in the left argument of a rule it is executed before the rule is applied. If it appears in the right argument it is executed once the rule has been applied. Trace procedures, _destru and _stop may appear on either side, but _goto, _failed and _repeat must only appear in the right argument of a rule.

Procedures in the left argument should be placed after weights and flags, and before any variables or terminal symbols. Procedures in the right argument should be placed after variables or terminal symbols.