next up previous
Next: Analysis and Transformation Up: Transforming COBOL Systems Previous: Unparsing

Patterns

We need a way to describe patterns for the recognition and transformation of code in a software renovation factory. The usual approach is to use open terms for this purpose: terms that represent a certain fixed pattern and contain variables at those positions where that pattern may vary.

A lesson that we learned from IT industry is that these patterns should be designed very carefully. The ideal situation is that the patterns for recognizing code resemble the code itself as much as possible.

Given the strong correspondence between concrete and abstract syntax in ASF+SDF (and the use of GLR parsing, see below), we can implement this requirement quite effectively. Given a grammar (in SDF) for some language we generate a so-called native pattern language [54] for it. This contains, amongst others, appropriately named variable declarations for each language construct. An example of a native COBOL pattern is shown in Figure 3. As can be seen, the COBOL pattern uses all the keywords that are already available in the COBOL standard [1]. Variables like procedure-name-1 and Statement-1+ act as placeholders in the pattern. For more details we refer to [54].

The generation of these patterns is facilitated by the use of GLR parsing. In [50] it is observed that grammars are often structured to permit ease of parsing and not ease of conceptual understanding, i.e., they are parser-oriented. In many cases, the grammar has to be expressed in an unnatural form to satisfy the restrictions that the parser generator imposes, such as one token look-ahead, and certain conflicts during parsing (see Section 6.2 or [43]). This same observation was made in the design of SDF [28].

The conclusion that one can draw from these observations is that it is a bad idea to use such a parser-oriented grammar for constructing other functionality like, e.g., the generation of a native pattern language. Since we use GLR parsing technology, there are no parser-related restrictions on the form of the grammar rules, we can write ``natural'' grammar rules, and therefore, the underlying structure of the native patterns is natural as well.

Figure 4: Example transformation that eliminates a GO TO.
\begin{figure}\begin{footnotesize}
\begin{verbatim}foo_Paragraph(
Procedure-na...
...dition-1
Statement-1+
END-PERFORM.\end{verbatim}\end{footnotesize}\end{figure}


next up previous
Next: Analysis and Transformation Up: Transforming COBOL Systems Previous: Unparsing
Paul Klint 2001-06-12