The aim of the preliminary transformation, presented in Figure 4, is to draw the general shape of the future attribute grammar. It introduces the attribute grammar profile with its semantic rules, and a unique semantic rule per each constructor pattern.
Figure 4: Preliminary transformation
The attribute result is defined as a synthesized attribute of the attribute grammar profile and contains the result of the function (rule Let'). For function with case statement the result is computed through attributes on the pattern-matched variable (rule Let). Other arguments are translated into semantic rules defining inherited attributes attached to the pattern-matched variable (rule Let). Each function call is translated into a dotted notation (rule App). This rule distinguishes between function and type constructor calls. Each expression appearing in a pattern is transformed into a semantic rule that defines the synthesized attribute computing the result (rule App). This induces some renaming (rule Pattern).
The application of the preliminary transformation to the flat function leads to: