Abstract
Many important tasks and algorithms in computer science build on sorted trees. Typical examples are the translation of programs represented by syntax trees or the processing of (recursive) data structures following some XML schema. In purely functional programming, sorted trees are usually implemented by terms of recursive data types such that a term represents a tree node and the subterms represent its children. The drawback of this representation is that the context of a tree node is not accessible and has to be managed by different means, e.g., by additional arguments of the functions working on the tree.
In this paper, we present a pattern for the realization of sorted trees that overcomes this drawback. The technique is fully declarative. In contrast to competing patterns for trees such as Zippers, it supports pattern matching on the tree data structure. Functions on tree nodes can be used to express the decoration of trees by attribute values in a flexible way. In particular, links between tree nodes can easily be defined and attributions can be modularized into phases with clear interfaces. Techniques adapted from the “Scrap your boilerplate” approach allow for the high-level specification of contextual constraints. We show how our approach can be realized in Haskell and discuss tool support.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Augusteijn, L.: The Elegant Compiler Generator System. In: Deransart, P., Jourdan, M. (eds.) Attribute Grammars and their Applications. LNCS, vol. 461, pp. 238–254. Springer, Heidelberg (1990)
Deransart, P., Jourdan, M., Lorho, B. (eds.): Attribute Grammars. LNCS, vol. 323. Springer, Heidelberg (1988)
Ganzinger, H.: Increasing modularity and language-independency in automatically generated compilers. Science of Computer Programming (1983)
Ganzinger, H., Giegerich, R.: Attribute coupled grammars. In: SIGPLAN 1984 Symposium on Compiler Construction, SIGPLAN Notices, vol. 19(6), pp. 157–170. ACM Press (1984)
Ganzinger, H., Giegerich, R., Möncke, U., Wilhelm, R.: A truly generative semantics-directed compiler generator. In: SIGPLAN 1982: Proceedings of the 1982 SIGPLAN Symposium on Compiler Construction, pp. 172–184. ACM Press (1982)
Hedin, G.: An Overview of Door Attribute Grammars. In: Fritzson, P.A. (ed.) CC 1994. LNCS, vol. 786, pp. 31–51. Springer, Heidelberg (1994)
Hendriks, P.R.H.: ASF system user’s guide. Technical Report CS-R8823, CWI (1988)
Hinze, R.: Memo functions, polytypically! In: Proceedings of the 2nd Workshop on Generic Programming, pp. 17–32 (2000)
Hinze, R., Jeuring, J.: Weaving a web. J. Funct. Program. 11(6), 681–689 (2001)
Huet, G.: The Zipper. Journal of Functional Programming 7(5), 549–554 (1997)
Johnson, T.: Attribute Grammars as a Functional Programming Paradigm. In: Kahn, G. (ed.) FPCA 1987. LNCS, vol. 274, pp. 154–173. Springer, Heidelberg (1987)
Jourdan, M., Parigot, D.: The FNC-2 system: Advances in attribute grammars technology. Technical Report No. 834, INRIA (April 1988)
Kastens, U.: Attributed Grammars as a Specification Method. In: Alblas, H., Melichar, B. (eds.) SAGA School 1991. LNCS, vol. 545, pp. 16–47. Springer, Heidelberg (1991)
Kastens, U., Hutt, B., Zimmermann, E. (eds.): GAG: A Practical Compiler Generator. LNCS, vol. 141. Springer, Heidelberg (1982)
Knuth, D.E.: The semantics of context-free languages. Mathematical Systems Theory (1968)
Lämmel, R.: Scrap your boilerplate with XPath-like combinators. In: POPL 2007, Proceedings. ACM Press (January 2007)
Lämmel, R., Peyton Jones, S.: Scrap your boilerplate: a practical design pattern for generic programming. In: ACM SIGPLAN Notices, Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation TLDI, vol. 38(3), pp. 26–37 (2003)
Lämmel, R., Peyton Jones, S.: Scrap more boilerplate: reflection, zips, and generalised casts. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2004), pp. 244–255. ACM Press (2004)
Michel, P.: Adding position structures to Katja. Technical Report 353/06, University of Kaiserslautern (June 2005)
Peyton Jones, S., Marlow, S., Elliott, C.: Stretching the Storage Manager: Weak Pointers and Stable Names in Haskell. In: Koopman, P., Clack, C. (eds.) IFL 1999. LNCS, vol. 1868, pp. 37–58. Springer, Heidelberg (2000)
Poetzsch-Heffter, A.: Prototyping realistic programming languages based on formal specifications. Acta Informatica 34, 737–772 (1997)
Poetzsch-Heffter, A., Rauch, N.: Application and Formal Specification of Sorted Term-Position Algebras. In: Fiadeiro, J.L., Mosses, P.D., Yu, Y. (eds.) WADT 2004. LNCS, vol. 3423, pp. 201–217. Springer, Heidelberg (2005)
Reps, T., Marceau, C., Teitelbaum, T.: Remote attribute updating for language-based editors. In: ACM-SIGPLAN ACM-SIGACT (ed.) Thirteenth Annual ACM Symposium on Principles of Programming Languages, pp. 1–13. ACM Press (January 1986)
Viera, M., Swierstra, S.D., Swierstra, W.: Attribute grammars fly first-class: how to do aspect oriented programming in haskell. In: Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP 2009, pp. 245–256. ACM, New York (2009)
Vogt, H., Swierstra, S., Kuiper, M.: Higher order attribute grammars. In: SIGPLAN 1989 Conference on Progamming Language Design and Implementation, SIGPLAN Notices, vol. 24(7), pp. 131–145. ACM Press (1989)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2013 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Gaillourdet, JM., Michel, P., Poetzsch-Heffter, A., Rauch, N. (2013). A Generic Functional Representation of Sorted Trees Supporting Attribution. In: Voronkov, A., Weidenbach, C. (eds) Programming Logics. Lecture Notes in Computer Science, vol 7797. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-37651-1_4
Download citation
DOI: https://doi.org/10.1007/978-3-642-37651-1_4
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-37650-4
Online ISBN: 978-3-642-37651-1
eBook Packages: Computer ScienceComputer Science (R0)