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

Modular specification and dynamic enforcement of syntactic language constraints when generating code
复制标题

生成代码时的模块化规范和句法语言约束的动态实施

DOI:
10.1145/2577080.2577089
复制
发表时间:
2014
期刊:
Proceedings of the 13th international conference on Modularity
影响因子:
--
通讯作者:
Eelco Visser
Eelco Visser
中科院分区:
--
文献类型:
--
作者:
Sebastian Erdweg;V. Vergu;Mira Mezini;Eelco Visser

文献摘要

被引文献

相似文献

元编程和生成式编程中的一个关键问题是保证生成的代码在目标语言的上下文无关和上下文敏感的约束下是格式良好的。我们提出类型智能构造函数作为一种动态的方法来强制生成的代码的格式良好。类型智能构造函数是一个用来代替常规构造函数来创建值的函数,但是如果给定的数据违反了某些特定于语言的约束,它可能会拒绝创建值。虽然类型智能构造函数可以单独实现,我们演示了如何从语法自动派生它们,使语法仍然是语言语法的唯一规范,并且不会重复。我们已经将对类型智能构造函数的支持集成到了TumblGo的运行时系统中,以便在调用常规构造函数时隐式地使用类型智能构造函数。我们评估的适用性,性能和实用性的类型智能构造器的语法约束,在编译器的MiniJava开发与Spoofax和各种语言扩展的Java和Haskell实现与SugarJ和SugarHaskell。
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.