skip to main content
10.1145/3571786.3573019acmconferencesArticle/Chapter ViewAbstractPublication PagespepmConference Proceedingsconference-collections
research-article

Efficient Embedding of Strategic Attribute Grammars via Memoization

Authors Info & Claims
Published:15 January 2023Publication History

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle Scholar
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarCross RefCross Ref
  7. Jonathan Cowie. 2005. Detecting Bad Smells in Haskell. University of Kent, UK. Google ScholarGoogle Scholar
  8. 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 ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. Gérard Huet. 1997. The Zipper. Journal of Functional Programming, 7, 5 (1997), Sept., 549–554. issn:0956-7968 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Donald E Knuth. 1968. Semantics of context-free languages. Mathematical systems theory, 2, 2 (1968), 127–145. Google ScholarGoogle Scholar
  14. 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 ScholarGoogle ScholarCross RefCross Ref
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle Scholar
  17. 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 ScholarGoogle Scholar
  18. 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 ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle Scholar
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle ScholarCross RefCross Ref
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle Scholar
  28. 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 ScholarGoogle Scholar
  29. 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 ScholarGoogle Scholar
  30. 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 ScholarGoogle Scholar
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Efficient Embedding of Strategic Attribute Grammars via Memoization

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in
        • Published in

          cover image ACM Conferences
          PEPM 2023: Proceedings of the 2023 ACM SIGPLAN International Workshop on Partial Evaluation and Program Manipulation
          January 2023
          65 pages
          ISBN:9798400700118
          DOI:10.1145/3571786

          Copyright © 2023 ACM

          Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 15 January 2023

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

          Acceptance Rates

          Overall Acceptance Rate66of120submissions,55%
        • Article Metrics

          • Downloads (Last 12 months)37
          • Downloads (Last 6 weeks)1

          Other Metrics

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader