ABSTRACT
Strategic term re-writing and attribute grammars are two powerful programming techniques widely used in language engineering. The former relies on strategies to apply term re-write rules in defining large-scale language transformations, while the latter is suitable to express context-dependent language processing algorithms. These two techniques can be expressed and combined via a powerful navigation abstraction: generic zippers. This results in a concise zipper-based embedding offering the expressiveness of both techniques.
Such elegant embedding has a severe limitation since it recomputes attribute values. This paper presents a proper and efficient embedding of both techniques. First, attribute values are memoized in the zipper data structure, thus avoiding their re-computation. Moreover, strategic zipper based functions are adapted to access such memoized values. We have implemented our memoized embedding as the Ztrategic library and we benchmarked it against the state-of-the-art Strafunski and Kiama libraries. Our first results show that we are competitive against those two well established libraries.
- Michael D. Adams. 2010. Scrap Your Zippers: A Generic Zipper for Heterogeneous Types. In WGP ’10: Proceedings of the 2010 ACM SIGPLAN workshop on Generic programming. ACM, New York, NY, USA. 13–24. isbn:978-1-4503-0251-7 https://doi.org/10.1145/1863495.1863499 Google ScholarDigital Library
- José Bacelar Almeida, Alcino Cunha, Nuno Macedo, Hugo Pacheco, and José Proença. 2018. Teaching How to Program Using Automated Assessment and Functional Glossy Games (Experience Report). Proc. ACM Program. Lang., 2, ICFP (2018), Article 82, July, 17 pages. https://doi.org/10.1145/3236777 Google ScholarDigital Library
- Emilie Balland, Paul Brauner, Radu Kopetz, Pierre-Etienne Moreau, and Antoine Reilles. 2007. Tom: Piggybacking Rewriting on Java. In Term Rewriting and Applications, Franz Baader (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 36–47. isbn:978-3-540-73449-9 Google Scholar
- R. S. Bird. 1984. Using Circular Programs to Eliminate Multiple Traversals of Data. Acta Informatica, January, 239–250. https://doi.org/10.1007/BF00264249 Google ScholarDigital Library
- Christoff Bürger. 2015. Reference Attribute Grammar Controlled Graph Rewriting: Motivation and Overview. In Proceedings of the 2015 ACM SIGPLAN International Conference on Software Language Engineering (SLE 2015). Association for Computing Machinery, New York, NY, USA. 89–100. isbn:9781450336864 https://doi.org/10.1145/2814251.2814257 Google ScholarDigital Library
- James R. Cordy. 2004. TXL - A Language for Programming Language Tools and Applications. Electronic Notes in Theoretical Computer Science, 110 (2004), 3–31. issn:1571-0661 https://doi.org/10.1016/j.entcs.2004.11.006 Proceedings of the Fourth Workshop on Language Descriptions, Tools, and Applications (LDTA 2004). Google ScholarCross Ref
- Jonathan Cowie. 2005. Detecting Bad Smells in Haskell. University of Kent, UK. Google Scholar
- Atze Dijkstra and S. Doaitse Swierstra. 2005. Typing Haskell with an Attribute Grammar. In Advanced Functional Programming, Varmo Vene and Tarmo Uustalu (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 1–72. isbn:978-3-540-31872-9 Google Scholar
- Torbjörn Ekman and Görel Hedin. 2007. The JastAdd extensible Java compiler. SIGPLAN Not., 42, 10 (2007), Oct., 1–18. issn:0362-1340 https://doi.org/10.1145/1297105.1297029 Google ScholarDigital Library
- João Paulo Fernandes, Pedro Martins, Alberto Pardo, João Saraiva, and Marcos Viera. 2019. Memoized zipper-based attribute grammars and their higher order extension. Sci. Comput. Program., 173 (2019), 71–94. https://doi.org/10.1016/j.scico.2018.10.006 Google ScholarDigital Library
- Robert W. Gray, Steven P. Levi, Vincent P. Heuring, Anthony M. Sloane, and William M. Waite. 1992. Eli: A Complete, Flexible Compiler Construction System. Commun. ACM, 35, 2 (1992), Feb., 121–130. issn:0001-0782 https://doi.org/10.1145/129630.129637 Google ScholarDigital Library
- Gérard Huet. 1997. The Zipper. Journal of Functional Programming, 7, 5 (1997), Sept., 549–554. issn:0956-7968 Google ScholarDigital Library
- Donald E Knuth. 1968. Semantics of context-free languages. Mathematical systems theory, 2, 2 (1968), 127–145. Google Scholar
- Donald E. Knuth. 1990. The genesis of attribute grammars. In Attribute Grammars and their Applications, P. Deransart and M. Jourdan (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 1–12. isbn:978-3-540-46666-6 https://doi.org/10.1007/3-540-53101-7_1 Google ScholarCross Ref
- Lucas Kramer and Eric Van Wyk. 2020. Strategic Tree Rewriting in Attribute Grammars. In Proceedings of the 13th ACM SIGPLAN International Conference on Software Language Engineering (SLE 2020). Association for Computing Machinery, New York, NY, USA. 210–229. isbn:9781450381765 https://doi.org/10.1145/3426425.3426943 Google ScholarDigital Library
- Matthijs Kuiper and João Saraiva. 1998. Lrc - A Generator for Incremental Language-Oriented Tools. In 7th International Conference on Compiler Construction, CC/ETAPS’98, Kay Koskimies (Ed.) (LNCS, Vol. 1383). Springer-Verlag, 298–301. Google Scholar
- Ralf Lämmel and Joost Visser. 2002. Typed Combinators for Generic Traversal. In Practical Aspects of Declarative Languages, Shriram Krishnamurthi and C. R. Ramakrishnan (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 137–154. isbn:978-3-540-45587-5 Google Scholar
- Sebastiaan P. Luttik and Eelco Visser. 1997. Specification of Rewriting Strategies. In Proceedings of the 2nd International Conference on Theory and Practice of Algebraic Specifications (Algebraic’97). BCS Learning & Development Ltd., Swindon, GBR. 9. isbn:3540762280 Google Scholar
- José Nuno Macedo, Marcos Viera, and João Saraiva. 2022. Zipping Strategies and Attribute Grammars. In Functional and Logic Programming - 16th International Symposium, FLOPS 2022, Kyoto, Japan, May 10-12, 2022, Proceedings, Michael Hanus and Atsushi Igarashi (Eds.) (Lecture Notes in Computer Science, Vol. 13215). Springer, 112–132. https://doi.org/10.1007/978-3-030-99461-7_7 Google ScholarDigital Library
- Pedro Martins, João Paulo Fernandes, and João Saraiva. 2013. Zipper-Based Attribute Grammars and Their Extensions. In Programming Languages, André Rauber Du Bois and Phil Trinder (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 135–149. isbn:978-3-642-40922-6 Google Scholar
- Pedro Martins, João Paulo Fernandes, João Saraiva, Eric Van Wyk, and Anthony Sloane. 2016. Embedding Attribute Grammars and Their Extensions Using Functional Zippers. Sci. Comput. Program., 132, P1 (2016), Dec., 2–28. issn:0167-6423 https://doi.org/10.1016/j.scico.2016.03.005 Google ScholarDigital Library
- Marjan Mernik, Nikolaj Korbar, and Viljem Žumer. 1995. LISA: A Tool for Automatic Language Implementation. SIGPLAN Not., 30, 4 (1995), April, 71–79. issn:0362-1340 https://doi.org/10.1145/202176.202185 Google ScholarDigital Library
- Thomas Reps and Tim Teitelbaum. 1984. The Synthesizer Generator. SIGPLAN Not., 19, 5 (1984), April, 42–48. issn:0362-1340 https://doi.org/10.1145/390011.808247 Google ScholarDigital Library
- João Saraiva. 2002. Component-Based Programming for Higher-Order Attribute Grammars. In Generative Programming and Component Engineering, ACM SIGPLAN/SIGSOFT Conference, GPCE 2002, Pittsburgh, PA, USA, October 6-8, 2002, Proceedings. 268–282. https://doi.org/10.1007/3-540-45821-2_17 Google ScholarCross Ref
- Tim Sheard and Simon Peyton Jones. 2002. Template Meta-Programming for Haskell. In Proceedings of the 2002 ACM SIGPLAN Workshop on Haskell (Haskell ’02). Association for Computing Machinery, New York, NY, USA. 1–16. isbn:1581136056 https://doi.org/10.1145/581690.581691 Google ScholarDigital Library
- Anthony M. Sloane, Lennart C. L. Kats, and Eelco Visser. 2010. A Pure Object-Oriented Embedding of Attribute Grammars. Electronic Notes in Theoretical Computer Science, 253, 7 (2010), 205–219. issn:1571-0661 https://doi.org/10.1016/j.entcs.2010.08.043 Google ScholarDigital Library
- Anthony M. Sloane, Matthew Roberts, and Leonard G. C. Hamey. 2014. Respect Your Parents: How Attribution and Rewriting Can Get Along. In Software Language Engineering, Benoît Combemale, David J. Pearce, Olivier Barais, and Jurgen J. Vinju (Eds.). Springer International Publishing, Cham. 191–210. isbn:978-3-319-11245-9 Google Scholar
- Emma Söderberg and Görel Hedin. 2013. Circular Higher-Order Reference Attribute Grammars. In Software Language Engineering, Martin Erwig, Richard F. Paige, and Eric Van Wyk (Eds.). Springer International Publishing, Cham. 302–321. isbn:978-3-319-02654-1 Google Scholar
- S. Doaitse Swierstra, Pablo R. Azero Alcocer, and João Saraiva. 1999. Designing and Implementing Combinator Languages. In Advanced Functional Programming, S. Doaitse Swierstra, José N. Oliveira, and Pedro R. Henriques (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 150–206. isbn:978-3-540-48506-3 Google Scholar
- Mark G. J. van den Brand, Arie van Deursen, Jan Heering, H. A. de Jong, Merijn de Jonge, Tobias Kuipers, Paul Klint, Leon Moonen, Pieter A. Olivier, Jeroen Scheerder, Jurgen J. Vinju, Eelco Visser, and Joost Visser. 2001. The ASF+SDF Meta-Environment: A Component-Based Language Development Environment. In Proceedings of the 10th International Conference on Compiler Construction (CC ’01). Springer-Verlag, Berlin, Heidelberg. 365–370. isbn:354041861X Google Scholar
- Eric Van Wyk, Derek Bodin, Jimin Gao, and Lijesh Krishnan. 2008. Silver: an Extensible Attribute Grammar System. Electronic Notes in Theoretical Computer Science, 203, 2 (2008), 103–116. issn:1571-0661 https://doi.org/10.1016/j.entcs.2008.03.047 Google ScholarDigital Library
- Eelco Visser. 2001. Stratego: A Language for Program Transformation Based on Rewriting Strategies. In Proceedings of the 12th International Conference on Rewriting Techniques and Applications (RTA ’01). Springer-Verlag, Berlin, Heidelberg. 357–362. isbn:3540421173 Google ScholarCross Ref
- H. H. Vogt, S. D. Swierstra, and M. F. Kuiper. 1989. Higher Order Attribute Grammars. SIGPLAN Not., 24, 7 (1989), jun, 131–145. issn:0362-1340 https://doi.org/10.1145/74818.74830 Google ScholarDigital Library
Index Terms
- Efficient Embedding of Strategic Attribute Grammars via Memoization
Recommendations
Nanopass Attribute Grammars
SLE 2023: Proceedings of the 16th ACM SIGPLAN International Conference on Software Language EngineeringCompilers for feature-rich languages are complex; they perform many analyses and optimizations, and often lower complex language constructs into simpler ones. The nanopass compiler architecture manages this complexity by specifying the compiler as a ...
Strategic tree rewriting in attribute grammars
SLE 2020: Proceedings of the 13th ACM SIGPLAN International Conference on Software Language EngineeringThis paper presents strategy attributes, a seamless integration of strategic term rewriting into attribute grammars. Strategy attributes are specified using rewrite rules with strategies that control their application. The rules can reference contextual ...
Zipping Strategies and Attribute Grammars
Functional and Logic ProgrammingAbstractStrategic term rewriting and attribute grammars are two powerful programming techniques widely used in language engineering. The former relies on strategies (recursion schemes) to apply term rewrite rules in defining transformations, while the ...
Comments