Languages and Notations

 

To present the basic steps of the FP-to-AG translation in a simple and clear way, we deliberately restrict ourselves to a sub-class of first order functional programsgif, presented in Figure 2. Notice that nested pattern-matching are not allowed, but it is easy to split them in several separated functions. Moreover, if-then-else can be taken into account with Dynamic Attribute Grammars [30]. We will not develop these points in this article, but other deforestation formalisms are dealing with similar classes of programs (cf. HYLO system [26]). The rev and flat programs given in introduction illustrate our functional language syntax (Figure 2).

   figure232
Figure 2: Functional language

To bring our attribute grammar notation, presented in Figure 3, closer to functional specifications, algebraic type definitions will be used instead of classical context free grammars [3, 12]. For example, types list and tree are defined as follows:

displaymath1477

A grammar production is represented as a data-type constructor followed by its parameter variables, that is, a pattern (for example: cons head tail).

   figure264
Figure 3: Attribute grammar notation

Since our transformations take type-checked functional programs as input, this induces information about the generated attribute grammars. For example, a distinctive feature of attribute grammars is to characterize two sorts of attributes: the synthesized ones are computed bottom-up over the structure and the inherited ones are computed top-down. The sort and the type of an attribute are directly deduced from the type-checked input programgif.

Furthermore, the notion of attribute grammar profile is introduced (in Figure 3, tex2html_wrap_inline1481 is the profile of f). It represents how to call the attribute grammar and allows result and arguments to be specified. This notion freely extends classical attribute grammars where these argument specifications were impossiblegif.

The occurrence of an attribute a on a pattern variable x is noted x.a. If an attribute is attached to the constructor of the current pattern, its occurrence is simply noted a gif. For instance, according to the attribute grammar syntax in Figure 3, the rev function is defined as follows:

displaymath1497

In further transformation algorithms, the following notations are used:

tex2html_wrap_inline1499  : local definition in an algorithm
tex2html_wrap_inline1501  : a n-tuple tex2html_wrap_inline1503
x.a = exp : semantic rule defining the attribute occurrence x.a
: substitution of x by y
tex2html_wrap_inline1515 : a set of semantic rules
tex2html_wrap_inline1517 : a pattern with its set of semantic rules
tex2html_wrap_inline1519 : transformation from A into B according to the local context tex2html_wrap_inline1525
tex2html_wrap_inline1527  : a term containing e as a sub-expression.


Web page maintained by Didier Parigot
Fri Feb 27 17:28:38 MET 1998