Hime Grammar Language - Template Rules

Repetitive and similar rules can be factorized using template rules. A template rule is a syntactic rule with parameters which can be invoked, passing values as arguments. A template rule is written as:

head<param1, ...> -> rule's body ;

There may be as many parameters as needed. In the rule's body, parameters may be directly referenced, as in head<param1> -> param1 ;. Template's parameters can also be used as arguments for the invocation of another template, as in:

a<x> -> x b<x> ;
b<y> -> y ;
s -> a<i> | a<j> ;

This is equivalent to:

ai -> i bi ;
bi -> i ;
aj -> j bj ;
bj -> j ;
s -> ai | aj ;