Strategic term rewriting and attribute grammars are two powerful programming techniques widely used in language engineering. The former, relies on strategies to apply term rewrite rules in defining language transformations, while the latter is suitable to express context-dependent language processing algorithms. Each of these techniques, however, is usually implemented by its own powerful and large language processor system. As a result, it makes such systems harder to extend and to combine. In this paper, we present the embedding of both strategic tree rewriting and attribute grammars in a zipper-based, purely functional setting. Zippers provide a simple, but generic tree-walk mechanism that is the building block technique we use to express the purely-functional embedding of both techniques. The embedding of the two techniques in the same setting has several advantages: First, we easily combine/zip attribute grammars and strategies, thus providing language engineers the best of the two worlds. Second, the combined embedding is easier to maintain and extend since it is written in a concise and uniform setting. This results in a very small library which is able to express advanced (static) analysis and transformation tasks. We show the expressive power of our library in optimizing |Haskell| let expressions, expressing several |Haskell| refactorings and solving several language processing tasks of the LDTA Tool Challenge.
翻译:战略术语重写和属性语法是语言工程中广泛使用的两种强有力的编程技术。前者依赖在定义语言转换时适用术语重写规则的战略,而后者则适合表达基于背景的语文处理算法。但这两种技术通常都由其本身的强大和大型语言处理系统实施。因此,这些系统更难扩展和合并。在本文件中,我们介绍了将战略树重写和属性语法都嵌入一个基于拉链的纯功能设置。Zippers提供了一个简单但通用的树行机制,这是我们用来表达两种技术纯功能嵌入的建筑块技术。在同一环境中嵌入两种技术有若干优点:首先,我们很容易地将语法和策略组合起来,从而向语言工程师提供两种世界的最佳语言。第二,合并嵌入更容易维护和扩展,因为它以简洁和统一的形式写成。这导致一个非常小的图书馆能够表达先进的(静态)树行走机制,这是我们用来表达两种技术纯功能嵌入的嵌入。在同一个环境中嵌入两种技术具有若干项权限的流程,我们展示了一种最先进的(动的)处理和变压式的版本。我们的方法。我们要的图书馆,我们展示了几种语言的版本。