skip to main content
research-article

From object algebras to attribute grammars

Published:15 October 2014Publication History
Skip Abstract Section

Abstract

Oliveira and Cook (2012) and Oliveira et al. (2013) have recently introduced object algebras as a program structuring technique to improve the modularity and extensibility of programs. We analyze the relationship between object algebras and attribute grammars (AGs), a formalism to augment context-free grammars with attributes. We present an extension of the object algebra technique with which the full class of L-attributed grammars - an important class of AGs that corresponds to one-pass compilers - can be encoded in Scala. The encoding is modular (attributes can be defined and type-checked separately), scalable (the size of the encoding is linear in the size of the AG specification) and compositional (each AG artifact is represented as a semantic object of the host language). To evaluate these claims, we have formalized the encoding and re-implemented a one-pass compiler for a subset of C with our technique. We also discuss how advanced features of modern AG systems, such as higher-order and parameterized attributes, reference attributes, and forwarding can be supported.

References

  1. G. V. Bochmann. Semantic evaluation from left to right. Communications of the ACM, 19(2):55--62, 1976. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. P. Buchlovsky and H. Thielecke. A type-theoretic reconstruction of the visitor pattern. In Proceedings of the Conference on Mathematical Foundations of Programming Semantics, pages 309--329. Elsevier ENTCS 155, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. J. Carette, O. Kiselyov, and C. Shan. Finally tagless, partially evaluated. In Proceedings of the Asian Symposium on Programming Languages and Systems, pages 222--238. Springer LNCS 4807, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. J. Carette, O. Kiselyov, and C. Shan. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming, 19(5):509--543, Sept. 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. L. M. Chirica and D. F. Martin. An order-algebraic definition of Knuthian semantics. Mathematical Systems Theory, 13:1--27, 1979.Google ScholarGoogle ScholarCross RefCross Ref
  6. O. De Moor, K. Backhouse, and S. D. Swierstra. First-class attribute grammars. Informatica, 24, 2000.Google ScholarGoogle Scholar
  7. P. Deransart, M. Jourdan, and B. Lorho. Attribute Grammars: Definitions, Systems, and Bibliography. Springer LNCS 323, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. É. Duris, D. Parigot, G. Roussel, and M. Jourdan. Attribute grammars and folds: Generic control operators. Rapport de recherche RR-2957, INRIA, 1996.Google ScholarGoogle Scholar
  9. J. Gibbons. Design patterns as higher-order datatype-generic programs. In Proceedings of the Workshop on Generic Programming, pages 1--12. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. G. Hedin. Reference attributed grammars. Informatica (Slovenia), 24(3):301--317, 2000.Google ScholarGoogle Scholar
  11. G. Hedin. An introductory tutorial on JastAdd attribute grammars. In Proceedings of the Summer School Conference on Generative and Transformational Techniques in Software Engineering, pages 166--200. Springer LNCS 6491, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. R. Hinze. Generics for the masses. In Proceedings of the International Conference on Functional Programming, pages 236--243. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. R. Hinze. Generics for the masses. Journal of Functional Programming, 16(4-5):451--483, July 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. C. Hofer, K. Ostermann, T. Rendel, and A. Moors. Polymorphic embedding of DSLs. In Proceedings of the Conference on Generative Programming and Component Engineering. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. T. Johnsson. Attribute grammars as a functional programming paradigm. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, pages 154--173, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. P. M. Lewis, D. J. Rosenkrantz, and R. E. Stearns. Attributed translations. Journal of Computer and System Sciences, 9(3):279--307, Dec. 1974. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. E. Magnusson and G. Hedin. Circular reference attributed grammars: Their evaluation and applications. Science of Computer Programming, 68(1):21--37, Aug. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. A. Middelkoop, A. Dijkstra, and S. D. Swierstra. Visitor-based attribute grammars with side effect. In Proceedings of the Workshop on Generative Technologies, pages 47--69. Elsevier ENTCS 264(5), 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. M. Odersky and M. Zenger. Independently extensible solutions to the expression problem. In Proceedings of the Workshop on Foundations of Object-Oriented Languages, 2005.Google ScholarGoogle Scholar
  20. B. C. Oliveira, M. Wang, and J. Gibbons. The visitor pattern as a reusable, generic, type-safe component. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications, pages 439--456. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. B. C. d. S. Oliveira and W. R. Cook. Extensibility for the masses: Practical extensibility with object algebras. In Proceedings of the European Conference on Object-Oriented Programming, pages 2--27. Springer LNCS 7313, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. B. C. d. S. Oliveira and J. Gibbons. Typecase: A design pattern for type-indexed functions. In Proceedings of the Haskell Workshop. ACM, 2005. ISBN 1-59593-071-X. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. B. C. d. S. Oliveira, T. van der Storm, A. Loh, and W. R. Cook. Feature-oriented programming with object algebras. In Proceedings of the European Conference on Object-Oriented Programming. Springer LNCS 7920, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. J. Paakki. Attribute grammar paradigms: A high-level methodology in language implementation. ACM Computing Surveys, 27(2):196--255, June 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. A. M. Sloane, L. C. Kats, and E. Visser. A pure embedding of attribute grammars. Science of Computer Programming, 78(10):1752--1769, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. S. D. Swierstra, P. R. Azero Alcocer, and J. Saraiva. Designing and implementing combinator languages. In Advanced Functional Programming, pages 150--206, 1998.Google ScholarGoogle Scholar
  27. E. Van Wyk, O. De Moor, K. Backhouse, and P. Kwiatkowski. Forwarding in attribute grammars for modular language design. In Proceedings of the Conference on Compiler Construction, pages 128--142. Springer LNCS 2304, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. E. Van Wyk, L. Krishnan, A. Schwerdfeger, and D. Bodin. Attribute grammar-based language extensions for Java. In Proceedings of the European Conference on Object-Oriented Programming. Springer LNCS 4609, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. M. Viera, S. D. Swierstra, andW. Swierstra. Attribute grammars fly first-class: How to do aspect oriented programming in Haskell. In Proceedings of the International Conference on Functional Programming, pages 245--256. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. H. H. Vogt, S. D. Swierstra, and M. F. Kuiper. Higher order attribute grammars. In Proceedings of the Conference on Programming Language Design and Implementation, pages 131--145. ACM, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. P. Wadler. The expression problem. Note to Java Genericity mailing list, Nov. 1998.Google ScholarGoogle Scholar

Index Terms

  1. From object algebras to attribute grammars

        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

        Full Access

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!