Next: , Previous: Constant Definition, Up: The Language


6.10 Rules

A rule is a sequence of statements that is executed as a unit:

     combi_rule name($param1, $param2, ...):
       statement1
       statement2
       ...
     end name;

A rule has to begin with one of the keywords allo_rule, combi_rule, end_rule, pruning_rule, robust_rule, input_filter, output_filter or subrule. It is followed by its parameter list, a list of variable names. The variables will be assigned the parameter values when the rule is executed. The number of parameters depends on the rule type. The rule names have the following meanings:

allo_rule ($lex_entry)
An allo-rule must occur exactly once in an allomorph rule file. It analyses a lexical entry and must generate one or more allomorph entries via result. An allomorph rule has one parameter, namely the lexicon entry.
combi_rule ($state, $link, $surf, $index)
Any number of combi-rules may occur in a combi-rule file. Before processing such a rule, the link is read in, which is either the word form or the allomorph that follows the state's surface. The first parameter of the rule is the state's feature structure, the second is the link's feature structure, the third is the link's surface, and the fourth is the link's index. The third and the fourth parameter are optional. A combi-rule may state a successor rule set or accept the analysed input (both via result).
end_rule ($state, $remain_input)
Any number of end-rules may occur in a combi-rule file. The first parameter is the state's feature structure, the second, which is optional, is the remaining input. If the rule takes only one parameter, it is only called if the remaining input is empty or begins with a space. An end rule may accept the analysed input via result.
pruning_rule ($list)
A pruning-rule may occur at most once in a syntax rule file. During syntax analysis, it can decide which states are still valid and which are to be deleted. The parameter is a list of feature structures of the states that have consumed the same input so far. The pruning-rule must execute a return statement with a list of the symbols yes and/or no. Each state in $list corresponds to a symbol in the result list. If the symbol is yes, the corresponding state is preserved. If the symbol is no, the state is abandoned.
robust_rule ($surface, $remain_input)
A robust-rule can only appear at most once a morphology rule file. If robust analysis has been switched on by the robust command, and a word form could not be recognised by the combi-rules, the robust-rule is executed with the surface of the next word form as its first parameter. The next word form is defined as the remaining input up to (but excluding) the next space. The optional second parameter contains the whole remaining input. A robust-rule can accept any prefix of the remaining input via result.
input_filter ($feature_structure_list)
An input-filter may occur at most once in a syntax rule file. The input-filter is called after a word form has been analysed. It gets one parameter, namely the list of the analysis results, and it transforms it to one or more filtered results (via result).
output_filter ($feature_structure_list)
An output-filter may occur at most once in any rule file.
In allo-rule files:
The output-filter is called after all lexicon entry have been processed by the allo-rules. The filter is called for every allomorph surface. It gets one parameter, namely the list of the generated feature structures with that surface, and it transforms it to one or more filtered allomorph feature structures (via result).
In combi-rule files:
The output-filter is called after an item has been analysed. It gets one parameter, namely the list of the analysis results, and it transforms it to one or more filtered results (via result).

subrule ($param1, $param2, ...)
Any number of subrules may occur in any rule file. A subrule can be invoked from other rules and it must return a value to this rule via return. It can have any number of parameters (at least one).

If a rule is executed, all statements in the rule are processed sequentially. After that, the rule execution is terminated. Thereby, the if statement, the foreach statement, and the parallel statement may change the processing order. Special conditions apply if:

  1. A condition in a require statement does not hold. In this case the processing of the current rule path is terminated. This is not an error.
  2. The stop statement was executed. In this case the processing of the current rule path is terminated. This is not an error.
  3. An assert condition does not hold. In this case the processing of the whole grammar is terminated and an error message is displayed. This rule termination can be used to find bugs in the rule system or in the lexicon.
  4. The error statement was executed. In this case the processing of the whole grammar is terminated and an error message is displayed.
  5. The return statement was executed in a subrule or in a pruning rule. In a subrule, this terminates the subrule int the current rule path and immediately returns to the calling rule. In a pruning rule, this terminates the pruning rule.