In addition to use the pattern-matching mechanism for finding some specifics FORTRAN constructions (see chapter 11), some script statements have been add in order to ease the comparison of AST at the script level.
SCRIPT UsePattern () pat := GETPAT ("(do ?v144 ?v145 (bounds ?index ?start ?end ?step) (?? ?body))") IF (MATCH (pat,$cstat)) THEN PRINT "the selection matches the pattern" PRINT ?index PRINT ?start PRINT ?end PRINT ?step PRINT ?body ELSE PRINT "the selection is different from the pattern" ENDIF ENDSCRIPT
Fortran code selection | Results | |
do 100 i = 1,ndim1 a(i) = var1 b(i) = var2 c(i) = var2 100 continue |
Display message ?index ?start ?end ?step ?body |
the selection matches the pattern i 1 ndim1 a(i) = var1 b(i) = var2 c(i) = var2 100 continue |
SCRIPT UsePattern () pattern := GETPAT(PARSESTAT(" c2(i,j) = 0")) PRINT pattern IF (MATCH (pat2,$csel)) THEN PRINT "the selection is equal to the pattern" ELSE PRINT "the selection is different from the pattern" ENDIF ENDSCRIPT
Fortran code selection | Results | |
c2(i,j) = 0 |
Display pattern Display message |
(ass (vardim c2 (l_exp i j)) 0) the selection matches the pattern |
SCRIPT SearchAllMatch () FIRST // set $cstat // pattern created from the pattern editor // we are looking for something like: // ?array1(?v117,?index) ?op ?array2(?index, ?v121) // we are interested by finding some expressions which involved two arrays // with the same indice between their rows and their columns pat := GETPAT ("(?op (vardim ?array1 (l_exp ?v117 ?index)) (vardim ?array2 (l_exp ?index ?v121)))") newMatch := NEXTMATCH(pat,$cstat) WHILE (newMatch) PRINT "" PRINT "A new match has been found" PRINT newMatch PRINT newMatch.ENCLOSINGSTAT // Get the enclosing statement newMatch := NEXTMATCH(pat,newMatch) ENDWHILE PRINT "No more match" // Note: can also use the Motif Builtin Dialog functions // to display message ENDSCRIPT
Fortran code | Results | |
... do k = 1,ndim2 c2(i,j) = a2(i,k)*b2(k,j) + c2(i,j) end do ... do 10 i = 1,ndim1,2 b(i) = c2(var2,i) + b2(i,1) c(i) = var2 0 continue ... |
First match Second match End of script |
A new match has been found a2(i,k)*b2(k,j) c2(i,j) = a2(i,k)*b2(k,j) + c2(i,j) A new match has been found c2(var2,i)+b2(i,1) b(i) = c2(var2,i) + b2(i,1) No more match |