ABSTRACT

Pattern matching of terms using the left-to-right tree automaton identifies a match (or lack thereof) after a single scan of the target term. Unnecessary positions may be inspected to ensure that no backtracking is needed when pattern matching fails. Using the left-to-right automaton with the adaptive strategy, the evaluation of the subterms rooted at inspected positions is forced in the left-to-right order. If such evaluations do not terminate, the evaluation of the subject term does not terminate either. However, the order of pattern matching terms need not be left-to-right. Sometimes, the evaluation of the same subject term would terminate if subterms were evaluated in a different order so that non-terminating evaluations might be avoided. We illustrate this through Example 12.1:

Consider the equational program with the following set of rewrite rules:

f (a,ω, a) → a (r1) f (a, b, b) → b (r2) c → c (r3)

where #f = 3 and as usual a, b, and c are constants. Consider the matching automata of Figure 12.1, wherein nonfinal states are labeled inside with the positions inspected and final states are labeled with the name of the matched rule.