The result of the preliminary transformation is not yet a real attribute
grammar. Each function definition in the initial program has been translated
into one block (cf. Figure 3) that contains the profile of the
function and its related patterns. But explicit recursive calls have been
translated into the form . Now, these expressions
have to be transformed into a set of more detailed semantic rules, breaking
explicit recursions by attribute naming and attachment to pattern
variables. Then, semantic rules will implicitly define the recursion
``à la'' attribute grammar. This transformation is achieved by the
profile symbolic evaluation, presented in Figure 5.
Figure 5: Profile Symbolic Evaluation
Everywhere an expression occurs, the profile
symbolic evaluation projects the semantic rules of the attribute grammar
profile f. The application of this transformation must be done with a
depth-first application strategy. The Check constraint ensures that
the resulting attribute grammar is well formed. Essentially, it verifies that
each attribute is defined once and only once. This is generally the case since
parameters in input functional programs are well-defined, but Check
forbid some non-linear terms such that
. Moreover, in
a first approach, terms like (x.a).b are not allowed but they will be treated
in section 3.2. Wherever
is not
verified, the expression
is simply rewrited in the
function call
.
In the previous flat example, the semantic rule associated to pattern node left right is
The application of (PSE) rule on this semantic rule is:
Finally, complete application of the profile symbolic evaluation leads for the function flat to the well-formed attribute grammar given below. The successive application of preliminary transformation and profile symbolic evaluation to an input functional program leads to a real attribute grammar. This is the FP-to-AG translation.