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 language | English (US) |
---|---|
Article number | 101033 |
Journal | Journal of Computer Languages |
Volume | 64 |
DOIs | |
State | Published - Jun 1 2021 |
Bibliographical note
Publisher Copyright:© 2021 Elsevier Ltd
Keywords
- Attribute grammars
- Object-language concrete syntax
- Reflection
- Term rewriting