Many tools used to process programs, like compilers, analyzers, or verifiers, perform transformations on their intermediate program representation, like abstract syntax trees. Implementing such program transformations is a non-trivial task, since it is necessary to iterate over the complete syntax tree and apply various transformations at nodes in a tree. In this paper we show how the features of functional logic programming are useful to implement program transformations in a compact and comprehensible manner. For this purpose, we propose to write program transformations as partially defined and non-deterministic operations. Since the implementation of non-determinism usually causes some overhead compared to deterministically defined operations, we compare our approach to a deterministic transformation method. We evaluate these alternatives for the functional logic language Curry and its intermediate representation FlatCurry which is used in various analysis and verification tools and compilers.
翻译:许多用于处理程序的工具,如编译器、分析器或验证器,都会对其中间程序表示(如抽象语法树)执行变换。实现此类程序变换是一项非平凡的任务,因为必须遍历完整的语法树并在树节点上应用各种变换。本文展示了函数式逻辑编程的特性如何有助于以紧凑且易于理解的方式实现程序变换。为此,我们提出将程序变换编写为部分定义且非确定性的操作。由于非确定性的实现通常比确定性定义的操作带来一定的开销,我们将我们的方法与一种确定性变换方法进行了比较。我们针对函数式逻辑语言Curry及其在多种分析、验证工具和编译器中使用的中间表示FlatCurry,对这些替代方案进行了评估。