Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/3357765.3359517acmconferencesArticle/Chapter ViewAbstractPublication PagesgpceConference Proceedingsconference-collections
research-article

Reflection in attribute grammars

Published: 21 October 2019 Publication History

Abstract

This paper shows how reflection on (undecorated) syntax trees used in attribute grammars can significantly reduce the amount of boiler-plate specifications that must be written. It is implemented in the Silver attribute grammar system in the form of a reflect function mapping syntax trees and other values into a generic representation and a reify function for the inverse mapping. We demonstrate its usefulness in several ways. The first is in an extension to Silver itself that simplifies writing language extensions for the ableC extensible C specification by allowing language engineers to specify C-language syntax trees using the concrete syntax of C (with typed holes) instead of writing abstract syntax trees. Secondly, a scrap-your-boilerplate style substitution mechanism is described. The third use is in serialization and de-serialization of the interface files Silver generates to support separate compilation; a custom interface language was replaced by a generic reflection-based implementation. Finally, an experimental implementation of staged interpreters for a small staged functional language is discussed.

Supplementary Material

MP4 File (3357765.3359517.mp4)
Presentation Video

References

[1]
John Tang Boyland. Remote attribute grammars. J. ACM, 52(4):627-687, 2005. ISSN 0004-5411.
[2]
M. G. J. van den Brand, A. van Deursen, J. Heering, H. A. de Jong, M. de Jonge, T. Kuipers, P. Klint, L. Moonen, P. A. Olivier, J. Scheerder, J. J. Vinju, E. Visser, and J. Visser. The ASF+SDF meta-environment: A component-based language development environment. In Proceedings of the Conference on Compiler Construction (CC), volume 2027 of Lecture Notes in Computer Science, pages 365-370, Berlin, Heidelberg, 2001. Springer Berlin Heidelberg.
[3]
Cristiano Calcagno, Walid Taha, Liwen Huang, and Xavier Leroy. Implementing multi-stage languages using ASTs, Gensym, and reflection. In Proceedings of the International Conference on Generative Programming and Component Engineering (GPCE), volume 2830 of Lecture Notes in Computer Science, pages 57-76. Springer, 2003.
[4]
Manuel Clavel and José Meseguer. Axiomatizing reflective logics and languages. In Proceedings of Reflection, pages 263-288, 1996.
[5]
François-Nicola Demers and Jacques Malenfant. Reflection in logic, functional and object-oriented programming: a short comparative study. In Proceedings of the IJCAII'95 Workshop on Reflection and Metalevel Architectures and their Applications in AI, pages 29-38, 1995.
[6]
Torbjörn Ekman and Görel Hedin. The JastAdd system - modular extensible compiler construction. Science of Computer Programming, 69:14-26, December 2007.
[7]
Sebastian Erdweg, Vlad Vergu, Mira Mezini, and Eelco Visser. Modular specification and dynamic enforcement of syntactic language constraints when generating code. In Proceedings of the 13th International Conference on Modularity, pages 241-252. ACM, 2014.
[8]
Andrzej Filinski. A semantic account of type-directed partial evaluation. In International Conference on Principles and Practice of Declarative Programming (PPDP), volume 1702 of Lecture Notes in Computer Science, pages 378-395. Springer, 1999.
[9]
G. Hedin. Reference attribute grammars. Informatica, 24(3):301-317, 2000.
[10]
Ted Kaminski and Eric Van Wyk. Modular well-definedness analysis for attribute grammars. In Proceedings of the 5th International Conference on Software Language Engineering (SLE 2012), volume 7745 of Lecture Notes in Computer Science, pages 352-371. Springer, September 2012.
[11]
Ted Kaminski, Lucas Kramer, Travis Carlson, and Eric Van Wyk. Reliable and automatic composition of language extensions to C: The ableC extensible language framework. Proceedings of the ACM on Programming Languages, 1(OOPSLA):98:1-98:29, October 2017a. ISSN 2475-1421.
[12]
Ted Kaminski, Lucas Kramer, Travis Carlson, and Eric Van Wyk. Reliable and automatic composition of language extensions to C -- supplemental material. Technical Report 17-009, University of Minnesota, Department of Computer Science and Engineering, 2017b. Available at https://www.cs.umn.edu/research/technical_reports/view/17-009.
[13]
Graham Kirby, Ron Morrison, and David Stemple. Linguistic reflection in Java. Software: Practice and Experience, 28(10):1045-1077, 1998.
[14]
Oleg Kiselyov. Reconciling abstraction with high performance: A metaocaml approach. Foundations and Trends in Programming Languages, 5(1):1-101, 2018.
[15]
Donald E. Knuth. Semantics of context-free languages. Mathematical Systems Theory, 2(2):127-145, 1968. Corrections in 5(1971) pp. 95-96.
[16]
Ralf Lämmel and Simon Peyton Jones. Scrap your boilerplate: A practical design pattern for generic programming. In Proceedings of the ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI), pages 26-37. ACM, 2003.
[17]
Ralf Lämmel and Simon Peyton Jones. Scrap more boilerplate: Reflection, zips, and generalised casts. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP), pages 244-255. ACM, 2004.
[18]
Lionel Parreaux, Amir Shaikhha, and Christoph E. Koch. Squid: Type-safe, hygienic, and reusable quasiquotes. In Proceedings of the ACM SIGPLAN International Symposium on Scala, pages 56-66, New York, NY, USA, 2017a. ACM.
[19]
Lionel Parreaux, Antoine Voizard, Amir Shaikhha, and Christoph E. Koch. Unifying analytic and statically-typed quasiquotes. Proceedings of the ACM on Programming Languages, 2(POPL):13:1-13:33, December 2017b.
[20]
Tim Sheard. Using MetaML: A staged programming language. In International School on Advanced Functional Programming (AFP), volume 1608 of Lecture Notes in Computer Science, pages 207-239. Springer, 1998.
[21]
Anthony M. Sloane. Lightweight language processing in Kiama. In Proceedings of the 3rd summer school on Generative and Transformational Techniques in Software Engineering III (GTTSE '09), volume 6491 of Lecture Notes in Computer Science, pages 408-425. Springer, 2011.
[22]
Brian Cantwell Smith. Procedural reflection in programming languages. PhD thesis, Massachusetts Institute of Technology, 1982.
[23]
Eric Van Wyk and August Schwerdfeger. Context-aware scanning for parsing extensible languages. In Proceedings of the International Conference on Generative Programming and Component Engineering (GPCE), pages 63-72, New York, NY, USA, 2007. ACM.
[24]
Eric Van Wyk, Oege de Moor, Kevin Backhouse, and Paul Kwiatkowski. Forwarding in attribute grammars for modular language design. In Proceedings of the Conference on Compiler Construction (CC), volume 2304 of Lecture Notes in Computer Science, pages 128-142. Springer-Verlag, 2002.
[25]
Eric Van Wyk, Derek Bodin, Jimin Gao, and Lijesh Krishnan. Silver: an extensible attribute grammar system. Science of Computer Programming, 75(1-2):39-54, January 2010.
[26]
Eelco Visser. Stratego: A language for program transformation based on rewriting strategies. System description of Stratego 0.5. In A. Middeldorp, editor, Rewriting Techniques and Applications (RTA'01), volume 2051 of Lecture Notes in Computer Science, pages 357-361. Springer-Verlag, May 2001.
[27]
Eelco Visser. Meta-programming with concrete object syntax. In Proceedings of the ACM SIPLAN International Conference on Generative Programming and Component Engineering (GPCE), volume 2487 of Lecture Notes in Computer Science, pages 299-315. Springer, 2002.
[28]
H. Vogt, S. D. Swierstra, and M. F. Kuiper. Higher-order attribute grammars. In Proceedings of the Conference on Programming Language Design and Implementation (PLDI), pages 131-145. ACM, 1989.

Cited By

View all
  • (2019)Parallel nondeterministic programming as a language extension to C (short paper)Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3357765.3359524(20-26)Online publication date: 21-Oct-2019

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM Conferences
GPCE 2019: Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences
October 2019
142 pages
ISBN:9781450369800
DOI:10.1145/3357765
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].

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 21 October 2019

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. attribute grammars
  2. meta-programming
  3. reflection

Qualifiers

  • Research-article

Conference

GPCE '19
Sponsor:

Acceptance Rates

Overall Acceptance Rate 56 of 180 submissions, 31%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)5
  • Downloads (Last 6 weeks)0
Reflects downloads up to 14 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2019)Parallel nondeterministic programming as a language extension to C (short paper)Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3357765.3359524(20-26)Online publication date: 21-Oct-2019

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