Macro Tree Transducers

  1. What is a Macro Tree Transducer?
  2. Example

What is a Macro Tree Transducer?

Macro tree transducers were introduced by Engelfriet in [Engelfriet, 1980]. They combine the features of top-down tree transducers [Rounds, 1970] and Fischer's macro grammars [Fischer, 1968]. The first extensive investigation can be found in [Engelfriet and Vogler, 1985]. Deterministic macro tree transducers are investigated in detail in [Fülöp and Vogler, 1998], where they are compared with other formal models of syntax-directed semantics.

In principle, macro tree transducers consist of rules, each of them meaning to transform a node of the input tree depending on the node's label. Subsequent functions are called for the children of the transformed node. This means, a macro tree transducer can be considered as a recursive first-order functional program generating trees, where the choice of functions is triggered by top-down pattern matching an input tree. During a computation, macro tree transducers may accumulate intermediate results in additional parameters, and thus have access to context information. Compared to the top-down tree transducer, the ability of carrying context information to further processing steps makes the macro tree transducer the more expressive model.

Formally, a stay macro tree transducer is defined as follows.

Definition A stay macro tree transducer M is defined by

(Q,Σ,Q0,R),

where
  • Q is the finite set of function names,
  • Σ is the finite ranked set of input and output symbols,
  • Q0Q is the set of initial functions, and
  • R is a finite set of rules of the two forms
    1. q(a(x1,..., xn), y1,... yk) → t or
    2. q(x0, y1,... yk) → t,
    where qQ is a function with k parameters (i.e. it is of rank k+1), symbol aΣ is of rank n, each xi (0≤in) denotes an input variable, each yj (1≤jk) is called accumulating parameter, and t is the right-hand side. Possible right-hand sides are composed as follows:
    1. every yj is a right-hand side,
    2. if t1,..., tn are right-hand sides and aΣ, then a(t1,...,tn) is also a right-hand side,
    3. if t1,..., tk are right-hand sides and qQ is of rank k, then q(xi, t1,...,tk) is also a right-hand side.
    Note that only those input variables xi are allowed in a right-hand side, that are specified in the according left-hand side, i.e. right-hand sides of rules of the second form contain only x0.

A similar definition can be found in [Maneth, Perst, and Seidl, 2007]. In [Perst, 2007]. additionally a formal definition of the semantics can be found. Since the function calls in right-hand sides can be nested, one has to carefully distinguish between inside-out and outside-in evaluation, because in general, both evaluation modes lead to different results.

The evaluation of a stay macro tree transducer M begins at the root node of the input. Given an input tree s0, M starts to process by evaluating one of its initial functions for the root node of s0. A function qQ with actual accumulating parameters t1,...,tk is applied to a subtree s=a(s1,...,sk) by carrying out the following steps. First, it is nondeterministically chosen one of the rules q(a(x1,..., xn), y1,... yk) → t or q(x0, y1,... yk) → t', for function q. If we have chosen a stay-rule, the current input tree s is substituted for the input variable x0 and the actual parameter tj for the accumulating variable yj in the right-hand side t. Otherwise, we substitute the subterms si and tj for the variables xi and yj in t'.

Example

The following macro tree transducer M generates an exact copy of its input, where the input is a binary tree consisting of symbols a and b, and with leafs labeled as e, i.e., for an example tree, M performs the follwing transformation:

binary tree
M
binary tree
M containes the following three rules:
q(a(x1,x2)) a(q(x1),q(x2))
q(b(x1,x2)) b(q(x1),q(x2))
q(e()) e()
where each rule defines the transformation for a specific input symbol.

Macro tree transducers with stay rules, on the other hand, have the ability to generate infinite many output trees for the same input tree. The following stay macro tree transducer, for example:

p(a(x1)) q(x1, a(p(x1))
p(e()) e()
q(x0, y) b(q(x0))
q(x0, y) y
inserts above every occurrence of an a an arbitrary long sequence of b's (or non at all). If for every symbol a function q evaluates to its parameter y, then the stay mtt copies its input tree. Otherwise, the transducer can generate for the input tree
binary tree
all trees of the form:
binary tree