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提供了一个简单但通用的树道机制,这是我们用来表达两种技术纯功能嵌入的建筑块技术。在同一环境中嵌入两种技术有若干优点:首先,我们很容易地将语法与战略结合起来/齐普属性,从而向语言工程师提供两种世界的最佳语言。第二,合并嵌入更容易维护和扩展,因为其以简洁和统一的设置为基础。这导致一个非常小的图书馆能够表达先进的(静态)树行走机制,这是我们用来表达两种技术纯功能嵌入两种技术的建筑块技术。在同一环境中嵌入这两种技术具有若干优点:首先,我们很容易地将拼写成一个表达我们最先进的(静)处理任务的图书馆,然后显示某种语言变压。