next up previous contents index
Next: Pattern Abstractors Up: Pattern-Matching Facilities Previous: Pattern-Matching Facilities

Pattern-Matching grammar

The TSF system offers the possibility to use pattern-matching to select Fortran statements. This pattern-matching is fairly standard and operates on the abstract syntax tree (AST) of the program. The current implementation has been derived from Norvig's algorithm which operates on non-structured lists. The syntax of the pattern description language is given table 4. The example 66 shows a pattern given in raw form and as a pseudo-Fortran form. The pseudo-Fortran form is the view produced by the pattern unparser that allows to hide pattern's syntax4.


  
Table 4: Grammar of the pattern language description. The pattern matching description refers to the abstract syntax tree
\begin{table}
\begin {center}
\begin {tabular} {\vert p{3cm}\vert p{3cm}\vert ...
...m & any nonvariable atom \\
\hline
\end {tabular}
\end {center}
\end{table}

$\vartriangleright$ Example 66:Pattern description example (raw and pseudo-Fortran forms  

  {\bf Raw form}
  (do ?name ?label (bounds ?index ?start ?end ?step)
  (l_stat 
    (ass (vardim ?array1 (l_exp (vardim ?indirect (l_exp ?index))))
      (?op
             (vardim ?array1 (l_exp (vardim ?indirect (l_exp ?index))))
             ?remainderExp))
  (?? ?enddoVar)))
pseudo-Fortran form
  ?name do ?label ?index = ?start, ?end, ?step 
    ?array1(?indirect(?index)) = ?array1(?indirect(?index)) 
              ?op ?remainderExp
  (?? ?enddoVar)

One originality of TSF lies in a set of functions that help the user to write pattern descriptions. The idea is to start from a Fortran program and to derive a pattern semi-automatically. These functions, called abstractors, generalize patterns according to a criterion. A typical usage of the abstractor starts by selecting a set of Fortran statements. From this set of statements an exact pattern is produced automatically by TSF. This pattern matches exactly the originally selected piece of Fortran code. If the user wishes to look for sets of statements with a similar syntactic structure but not exactly identical he can successively use the abstractor functions to achieve a generalization of the pattern. The pattern abstraction functions are described in the next section.


next up previous contents index
Next: Pattern Abstractors Up: Pattern-Matching Facilities Previous: Pattern-Matching Facilities
Yann Mevel
1999-04-30