TY - JOUR
T1 - Generalising tree traversals and tree transformations to DAGs
T2 - Exploiting sharing without the pain
AU - Bahr, Patrick
AU - Axelsson, Emil
PY - 2017/4/4
Y1 - 2017/4/4
N2 - We present a recursion scheme based on attribute grammars that can be transparently applied to trees and acyclic graphs. Our recursion scheme allows the programmer to implement a tree traversal or a tree transformation and then apply it to compact graph representations of trees instead. The resulting graph traversal or graph transformation avoids recomputation of intermediate results for shared nodes – even if intermediate results are used in different contexts. Consequently, this approach leads to asymptotic speedup proportional to the compression provided by the graph representation. In general, however, this sharing of intermediate results is not sound. Therefore, we complement our implementation of the recursion scheme with a number of correspondence theorems that ensure soundness for various classes of traversals. We illustrate the practical applicability of the implementation as well as the complementing theory with a number of examples.
AB - We present a recursion scheme based on attribute grammars that can be transparently applied to trees and acyclic graphs. Our recursion scheme allows the programmer to implement a tree traversal or a tree transformation and then apply it to compact graph representations of trees instead. The resulting graph traversal or graph transformation avoids recomputation of intermediate results for shared nodes – even if intermediate results are used in different contexts. Consequently, this approach leads to asymptotic speedup proportional to the compression provided by the graph representation. In general, however, this sharing of intermediate results is not sound. Therefore, we complement our implementation of the recursion scheme with a number of correspondence theorems that ensure soundness for various classes of traversals. We illustrate the practical applicability of the implementation as well as the complementing theory with a number of examples.
KW - Attribute grammars
KW - sharing
KW - graph traversal
KW - graph transformation
KW - directed acyclic graphs
U2 - 10.1016/j.scico.2016.03.006
DO - 10.1016/j.scico.2016.03.006
M3 - Journal article
SN - 0167-6423
VL - 137
SP - 63
EP - 97
JO - Science of Computer Programming
JF - Science of Computer Programming
ER -