In Figure 8, a tree pattern follows the match keyword. Tree patterns are written as S-expressions for convenience. The tree pattern in this example is compiled to the pattern matching code shown in the first part of Figure 9 (code for sections of the rule follow the comment containing that section).
The when expression, which contains arbitrary C code, guards the match, preventing the rest of the rule from being executed unless the expression evaluates to true. The build statement creates a new subtree, taking care to copy subtrees from the matched tree, since those subtrees are likely to be deleted by a replace command.
The tracking necessary for debugging and transformation replay is performed
at a low-level in the KHEPERA library. However, the KHEPERA language
translator automatically adds functions (with names starting with
trk_) to the generated rules. These functions add high-level
descriptive information which allows fine-grain navigation during
transformation reply, but which is not necessary for answering debugger
A more complicated KHEPERA rule is shown in Figure 10. This rule implements the third sequence comprehension elimination transformation (Rule 3 from Section 4.3).
The example in Figure 10 uses the children statement to iterate
over the children of the
N_ExpressionList node, and uses the
do statement as a general-purpose escape to C. This escape
mechanism is used to build up a new list with the
function, and to modify an implementor-defined attribute (prime).
KHEPERA language features not discussed here include the use of a conditional if-then-else statement in place of a when statement, the ability to break out of a children loop, and the ability to perform tree traversals of matched subtree sections (this is useful when an expression must be examined to determine if it is independent of some variable under consideration).