Respect Your Parents: How Attribution and Rewriting Can Get Along

  • Anthony M. Sloane
  • Matthew Roberts
  • Leonard G. C. Hamey
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8706)


Attribute grammars describe how to decorate static trees. Rewriting systems describe how to transform trees into new trees. Attribution is undermined by rewriting because a node may appear in both the source and product of a transformation. If an attribute of that node depends on the node’s context, then a previously computed value may not be valid. We explore this problem and formalise it as a question of ancestry: the context of a node is given by the tree’s parent relationships and we must use the appropriate parents to calculate attributes that depend on the context. We show how respecting parents naturally leads to a view of context-dependent attributes as tree-indexed attribute families. Viewed in this way, attribution co-exists easily with rewriting transformations. We demonstrate the practicality of our approach by describing our implementation in the Kiama language processing library.


Pattern Match Tree Node Attribute Evaluation Parent Relationship Functional Language 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    van den Brand, M.G.J., Klint, P.: ATerms for manipulation and exchange of structured data: It’s all about sharing. Information and Software Technology 49(1), 55–64 (2007)CrossRefGoogle Scholar
  2. 2.
    Sloane, A.M.: Lightweight language processing in kiama. In: Fernandes, J.M., Lämmel, R., Visser, J., Saraiva, J. (eds.) Generative and Transformational Techniques in Software Engineering III. LNCS, vol. 6491, pp. 408–425. Springer, Heidelberg (2011)CrossRefGoogle Scholar
  3. 3.
    Sloane, A.M., Kats, L.C.L., Visser, E.: A pure embedding of attribute grammars. Science of Computer Programming 78, 1752–1769 (2013)CrossRefGoogle Scholar
  4. 4.
    Hedin, G., Magnusson, E.: JastAdd: an aspect-oriented compiler construction system. Science of Computer Programming 47(1), 37–58 (2003)CrossRefzbMATHMathSciNetGoogle Scholar
  5. 5.
    Van Wyk, E., Bodin, D., Gao, J., Krishnan, L.: Silver: An extensible attribute grammar system. Science of Computer Programming 75, 39–54 (2010)CrossRefzbMATHMathSciNetGoogle Scholar
  6. 6.
    Bravenboer, M., Kalleberg, K.T., Vermaas, R., Visser, E.: Stratego/XT 0.16: components for transformation systems. In: Proceedings of the 2006 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, pp. 95–99. ACM (2006)Google Scholar
  7. 7.
    Odersky, M., Spoon, L., Venners, B.: Programming in Scala, 2nd edn. Artima Press (2010)Google Scholar
  8. 8.
    Emir, B., Odersky, M., Williams, J.: Matching objects with patterns. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 273–298. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  9. 9.
    Reps, T.W.: Generating Language-based Environments. Massachusetts Institute of Technology, Cambridge (1984)zbMATHGoogle Scholar
  10. 10.
    Saraiva, J., Swierstra, S.D., Kuiper, M.: Functional incremental attribute evaluation. In: Watt, D.A. (ed.) CC 2000. LNCS, vol. 1781, pp. 279–294. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  11. 11.
    Bransen, J., Dijkstra, A., Swierstra, S.D.: Lazy stateless incremental evaluation machinery for attribute grammars. In: Proceedings of the Workshop on Partial Evaluation and Program Manipulation, pp. 145–156. ACM (2014)Google Scholar
  12. 12.
    Bürger, C.: RACR: A Scheme Library for Reference Attribute Grammar Controlled Rewriting. Dresden University of Technology (2014),
  13. 13.
    Magnusson, E., Hedin, G.: Circular reference attributed grammars–their evaluation and applications. Science of Computer Programming 68(1), 21–37 (2007)CrossRefzbMATHMathSciNetGoogle Scholar
  14. 14.
    Ekman, T., Hedin, G.: Rewritable reference attributed grammars. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 147–171. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  15. 15.
    Van Wyk, E., de Moor, O., Backhouse, K., Kwiatkowski, P.: Forwarding in attribute grammars for modular language design. In: Nigel Horspool, R. (ed.) CC 2002. LNCS, vol. 2304, pp. 128–142. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  16. 16.
    Johnsson, T.: Attribute grammars as a functional programming paradigm. In: Kahn, G. (ed.) FPCA 1987. LNCS, vol. 274, pp. 154–173. Springer, Heidelberg (1987)CrossRefGoogle Scholar
  17. 17.
    Adams, M.D.: Scrap your zippers: a generic zipper for heterogeneous types. In: Proceedings of the ACM SIGPLAN Workshop on Generic Programming, pp. 13–24. ACM (2010)Google Scholar
  18. 18.
    Martins, P., Fernandes, J.P., Saraiva, J.: Zipper-based attribute grammars and their extensions. In: Du Bois, A.R., Trinder, P. (eds.) SBLP 2013. LNCS, vol. 8129, pp. 135–149. Springer, Heidelberg (2013)CrossRefGoogle Scholar
  19. 19.
    Gaillourdet, J.-M., Michel, P., Poetzsch-Heffter, A., Rauch, N.: A generic functional representation of sorted trees supporting attribution. In: Voronkov, A., Weidenbach, C. (eds.) Programming Logics. LNCS, vol. 7797, pp. 72–89. Springer, Heidelberg (2013), CrossRefGoogle Scholar
  20. 20.
    Kats, L., Sloane, A.M., Visser, E.: Decorated attribute grammars: Attribute evaluation meets strategic programming. In: de Moor, O., Schwartzbach, M.I. (eds.) CC 2009. LNCS, vol. 5501, pp. 142–157. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  21. 21.
    Linton, M.A.: Implementing relational views of programs. In: Proceedings of the Symposium on Practical Software Development Environments, pp. 132–140. ACM (1984)Google Scholar
  22. 22.
    Klint, P., van der Storm, T., Vinju, J.: EASY meta-programming with rascal. In: Fernandes, J.M., Lämmel, R., Visser, J., Saraiva, J. (eds.) Generative and Transformational Techniques in Software Engineering III. LNCS, vol. 6491, pp. 222–289. Springer, Heidelberg (2011)CrossRefGoogle Scholar

Copyright information

© Springer International Publishing Switzerland 2014

Authors and Affiliations

  • Anthony M. Sloane
    • 1
  • Matthew Roberts
    • 1
  • Leonard G. C. Hamey
    • 1
  1. 1.Department of ComputingMacquarie UniversitySydneyAustralia

Personalised recommendations