Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article

From object algebras to attribute grammars

Published: 15 October 2014 Publication History

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.
[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.
[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.
[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.
[5]
L. M. Chirica and D. F. Martin. An order-algebraic definition of Knuthian semantics. Mathematical Systems Theory, 13:1--27, 1979.
[6]
O. De Moor, K. Backhouse, and S. D. Swierstra. First-class attribute grammars. Informatica, 24, 2000.
[7]
P. Deransart, M. Jourdan, and B. Lorho. Attribute Grammars: Definitions, Systems, and Bibliography. Springer LNCS 323, 1988.
[8]
É. Duris, D. Parigot, G. Roussel, and M. Jourdan. Attribute grammars and folds: Generic control operators. Rapport de recherche RR-2957, INRIA, 1996.
[9]
J. Gibbons. Design patterns as higher-order datatype-generic programs. In Proceedings of the Workshop on Generic Programming, pages 1--12. ACM, 2006.
[10]
G. Hedin. Reference attributed grammars. Informatica (Slovenia), 24(3):301--317, 2000.
[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.
[12]
R. Hinze. Generics for the masses. In Proceedings of the International Conference on Functional Programming, pages 236--243. ACM, 2004.
[13]
R. Hinze. Generics for the masses. Journal of Functional Programming, 16(4-5):451--483, July 2006.
[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.
[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.
[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.
[17]
E. Magnusson and G. Hedin. Circular reference attributed grammars: Their evaluation and applications. Science of Computer Programming, 68(1):21--37, Aug. 2007.
[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.
[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.
[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.
[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.
[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.
[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.
[24]
J. Paakki. Attribute grammar paradigms: A high-level methodology in language implementation. ACM Computing Surveys, 27(2):196--255, June 1995.
[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.
[26]
S. D. Swierstra, P. R. Azero Alcocer, and J. Saraiva. Designing and implementing combinator languages. In Advanced Functional Programming, pages 150--206, 1998.
[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.
[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.
[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.
[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.
[31]
P. Wadler. The expression problem. Note to Java Genericity mailing list, Nov. 1998.

Cited By

View all
  • (2019)Solving the Expression Problem in C++, á la LMSTheoretical Aspects of Computing – ICTAC 201910.1007/978-3-030-32505-3_20(353-371)Online publication date: 22-Oct-2019
  • (2016)Compositional Language Engineering Using Generated, Extensible, Static Type-Safe VisitorsProceedings of the 12th European Conference on Modelling Foundations and Applications - Volume 976410.1007/978-3-319-42061-5_5(67-82)Online publication date: 6-Jul-2016
  • (2024)Imperative Compositional Programming: Type Sound Distributive Intersection Subtyping with References via Bidirectional TypingProceedings of the ACM on Programming Languages10.1145/36897828:OOPSLA2(2010-2039)Online publication date: 8-Oct-2024
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM SIGPLAN Notices
ACM SIGPLAN Notices  Volume 49, Issue 10
OOPSLA '14
October 2014
907 pages
ISSN:0362-1340
EISSN:1558-1160
DOI:10.1145/2714064
  • Editor:
  • Andy Gill
Issue’s Table of Contents
  • cover image ACM Conferences
    OOPSLA '14: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications
    October 2014
    946 pages
    ISBN:9781450325851
    DOI:10.1145/2660193
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 the author(s) 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 October 2014
Published in SIGPLAN Volume 49, Issue 10

Check for updates

Author Tags

  1. attribute grammars
  2. church-encoding
  3. embedded domain-specific languages
  4. modularity
  5. object algebras
  6. one-pass compilers
  7. scala
  8. visitor pattern

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)12
  • Downloads (Last 6 weeks)1
Reflects downloads up to 11 Jan 2025

Other Metrics

Citations

Cited By

View all
  • (2019)Solving the Expression Problem in C++, á la LMSTheoretical Aspects of Computing – ICTAC 201910.1007/978-3-030-32505-3_20(353-371)Online publication date: 22-Oct-2019
  • (2016)Compositional Language Engineering Using Generated, Extensible, Static Type-Safe VisitorsProceedings of the 12th European Conference on Modelling Foundations and Applications - Volume 976410.1007/978-3-319-42061-5_5(67-82)Online publication date: 6-Jul-2016
  • (2024)Imperative Compositional Programming: Type Sound Distributive Intersection Subtyping with References via Bidirectional TypingProceedings of the ACM on Programming Languages10.1145/36897828:OOPSLA2(2010-2039)Online publication date: 8-Oct-2024
  • (2021)Compositional ProgrammingACM Transactions on Programming Languages and Systems10.1145/346022843:3(1-61)Online publication date: 3-Sep-2021
  • (2020)Pattern matching in an open worldACM SIGPLAN Notices10.1145/3393934.327812453:9(134-146)Online publication date: 7-Apr-2020
  • (2020)Castor: Programming with extensible generative visitorsScience of Computer Programming10.1016/j.scico.2020.102449(102449)Online publication date: Mar-2020
  • (2019)Distributive Disjoint Polymorphism for Compositional ProgrammingProgramming Languages and Systems10.1007/978-3-030-17184-1_14(381-409)Online publication date: 6-Apr-2019
  • (2018)Pattern matching in an open worldProceedings of the 17th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3278122.3278124(134-146)Online publication date: 5-Nov-2018
  • (2017)Reliable and automatic composition of language extensions to C: the ableC extensible language frameworkProceedings of the ACM on Programming Languages10.1145/31382241:OOPSLA(1-29)Online publication date: 12-Oct-2017
  • (2017)Disjoint PolymorphismProgramming Languages and Systems10.1007/978-3-662-54434-1_1(1-28)Online publication date: 19-Mar-2017
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media