Anthony M. Sloane Matthew Roberts Leonard G. C. Hamey Programming Languages Research Group Department of Computing Macquarie University [email protected] @inkytonik 1 / 24
many attributes need to consider nodes in context Rewriting: transforming tree A into tree B it is common to share nodes between trees Problem: if a node is shared between Tree A and Tree B, what is its context? 2 / 24
root with the relations defined by reachability child, parent, siblings, prev, next, . . . Attribute families Context-dependent attributes are families, indexed by a tree Family definitions use the tree relations to access the context 10 / 24
,Node ]) { val depth : Node => Int = attr { case tree.parent (p) => depth (p) + 1 case _ => 0 } } val root : Node = ... val tree = new Tree[Node ,Node] (root) val n : Node = ... val depthModule = new DepthModule (tree) ... depthModule.depth (n) ... 20 / 24
a relation between T and U and the attribute anAttr is applied to a value t of type T val r : Relation[T,U] = ... val anAttr : T => V = attr { case r (p1) => // if (t,u) in r and p1 matches u case r.pair (p0 , p1) => // if (t,u) in r, p0 matches t and p1 matches u } 21 / 24
of Tree and Relation. Converted our extensive test suite including Prolog, Oberon-0 and MiniJava compilers (over 11,000 lines of Scala) to use attribute families. Results: Analysis objects are now analysis modules. Attribute definitions are often simpler with relational pattern matching. Rewriting didn’t change at all. No discernible differences in performance of sequential testing. Parallel testing of attribution on shared trees is now possible. 23 / 24
tree many attributes need to consider nodes in context Rewriting: transforming tree A into tree B it is common to share nodes between trees Problem: if a node is shared, what is its context? Solution: trees make contexts explicit via node relations attribute families are defined generically on trees first-class relations provide pattern matching support implemented in upcoming Kiama 2.0 (kiama.googlecode.com) Scala is a powerful host language. . . 24 / 24