Reflection of terms in attribute grammars: Design and applications

Lucas Kramer, Ted Kaminski, Eric Van Wyk

Research output: Contribution to journalArticlepeer-review

Abstract

This paper shows how reflection on undecorated syntax trees (terms) used in attribute grammars can significantly reduce the amount of boiler-plate specifications that must be written. The proposed reflection system is implemented in the form of a [Formula presented] function mapping terms and other values into a generic representation and a [Formula presented] function for the inverse mapping. The system is implemented in the SILVER attribute grammar system. We demonstrate the usefulness of this approach to reflection in attribute grammars in several ways. The first use is in the 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. Secondly, we describe 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. Third, strategic term rewriting in the style of STRATEGO is implemented using reflection as a library for, and extension to, SILVER. Finally, an experimental implementation of staged interpreters for a small staged functional language is discussed.

Original languageEnglish (US)
Article number101033
JournalJournal of Computer Languages
Volume64
DOIs
StatePublished - Jun 1 2021

Bibliographical note

Publisher Copyright:
© 2021 Elsevier Ltd

Keywords

  • Attribute grammars
  • Object-language concrete syntax
  • Reflection
  • Term rewriting

Fingerprint

Dive into the research topics of 'Reflection of terms in attribute grammars: Design and applications'. Together they form a unique fingerprint.

Cite this