Modular specification and dynamic enforcement of syntactic language constraints when generating code

Conference Paper (2014)
Author(s)

S.T. Erdweg (Technische Universität Darmstadt)

Vlad Vergu (TU Delft - Programming Languages)

Mira Mezini (Technische Universität Darmstadt)

Eelco Visser (TU Delft - Programming Languages)

Research Group
Programming Languages
Copyright
© 2014 S.T. Erdweg, V.A. Vergu, Mira Mezini, Eelco Visser
DOI related publication
https://doi.org/10.1145/2577080.2577089
More Info
expand_more
Publication Year
2014
Language
English
Copyright
© 2014 S.T. Erdweg, V.A. Vergu, Mira Mezini, Eelco Visser
Research Group
Programming Languages
Pages (from-to)
241-252
ISBN (print)
978-1-4503-2772-5
Reuse Rights

Other than for strictly personal use, it is not permitted to download, forward or distribute the text or part of it, without the consent of the author(s) and/or copyright holder(s), unless the work is under an open content license such as Creative Commons.

Abstract

A key problem in metaprogramming and specifically in generative programming is to guarantee that generated code is well-formed with respect to the context-free and context-sensitive constraints of the target language. We propose typesmart constructors as a dynamic approach to enforcing the well-formedness of generated code. A typesmart constructor is a function that is used in place of a regular constructor to create values, but it may reject the creation of values if the given data violates some language-specific constraint. While typesmart constructors can be implemented individually, we demonstrate how to derive them automatically from a grammar, so that the grammar remains the sole specification of a language's syntax and is not duplicated. We have integrated support for typesmart constructors into the run-time system of Stratego to enforce usage of typesmart constructors implicitly whenever a regular constructor is called. We evaluate the applicability, performance, and usefulness of typesmart constructors for syntactic constraints in a compiler for MiniJava developed with Spoofax and in various language extensions of Java and Haskell implemented with SugarJ and SugarHaskell.

Files

P241_erdweg.pdf
(pdf | 0.712 Mb)
Unspecified