Reflection in Attribute Grammars

Lucas Kramer, Ted Kaminski, Eric Van Wyk

Research output: Chapter in Book/Report/Conference proceedingConference contribution

1 Scopus citations

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.

Original languageEnglish (US)
Title of host publicationGPCE 2019 - Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming
Subtitle of host publicationConcepts and Experiences, co-located with SPLASH 2019
EditorsIna Schaefer, Christoph Reichenbach, Tijs van der Storm
PublisherAssociation for Computing Machinery, Inc
Pages48-60
Number of pages13
ISBN (Electronic)9781450369800
DOIs
StatePublished - Oct 21 2019
Event18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences, GPCE 2019, co-located with ACM SIGPLAN Conference on Systems, Programming, Languages, and Applications: Software for Humanity, SPLASH 2019 - Athens, Greece
Duration: Oct 21 2019Oct 22 2019

Publication series

NameGPCE 2019 - Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences, co-located with SPLASH 2019

Conference

Conference18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences, GPCE 2019, co-located with ACM SIGPLAN Conference on Systems, Programming, Languages, and Applications: Software for Humanity, SPLASH 2019
CountryGreece
CityAthens
Period10/21/1910/22/19

    Fingerprint

Keywords

  • Attribute grammars
  • Meta-programming
  • Reflection

Cite this

Kramer, L., Kaminski, T., & Van Wyk, E. (2019). Reflection in Attribute Grammars. In I. Schaefer, C. Reichenbach, & T. van der Storm (Eds.), GPCE 2019 - Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences, co-located with SPLASH 2019 (pp. 48-60). (GPCE 2019 - Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences, co-located with SPLASH 2019). Association for Computing Machinery, Inc. https://doi.org/10.1145/3357765.3359517