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

Sebastian Erdweg, Vlad Vergu, Mira Mezini, Eelco Visser

Research output: Chapter in Book/Conference proceedings/Edited volumeConference contributionScientificpeer-review

7 Citations (Scopus)
34 Downloads (Pure)


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.
Original languageEnglish
Title of host publicationMODULARITY '14
Subtitle of host publicationProceedings of the 13th international conference on Modularity
Place of PublicationNew York, NY
PublisherAssociation for Computing Machinery (ACM)
Number of pages12
ISBN (Print)978-1-4503-2772-5
Publication statusPublished - 2014
Event13th International Conference on Modularity - Lugano, Switzerland
Duration: 22 Apr 201426 Apr 2014
Conference number: 13


Conference13th International Conference on Modularity
Abbreviated titleModularity 2014


Dive into the research topics of 'Modular specification and dynamic enforcement of syntactic language constraints when generating code'. Together they form a unique fingerprint.

Cite this