用程序骨架抽象代码结构,实现跨语言自动翻译。
Program Skeletons for Automated Program Translation
- 通过骨架抽象低层代码,保留高层结构
- 95%代码可自动翻译,5%需人工干预
- 适合需要跨语言迁移的开发者
在不同编程语言间自动翻译软件是一项挑战性任务,现有技术难以规模化。核心难点在于需将源程序的行为重表达为目标语言的惯用形式,同时剥离源语言特有细节并保持功能一致。本文提出基于程序骨架的新方法,通过抽象和总结底层代码片段来保留源程序的高层结构,并可机械地映射到目标语言。骨架允许多种实现填充方式,与数据驱动的代码合成器协同工作。关键优势在于支持可靠分解:只要每个片段正确翻译,整体程序即视为正确。我们构建了名为Skel的原型系统,实现从Python到JavaScript的翻译。对9个真实世界程序(部分超过1000行)测试显示,95%代码片段可自动翻译,约5%需手动处理;所有最终翻译均通过全程序测试套件验证正确。
原文摘要 · Abstract (English)
Translating software between programming languages is a challenging task, for which automated techniques have been elusive and hard to scale up to larger programs. A key difficulty in cross-language translation is that one has to re-express the intended behavior of the source program into idiomatic constructs of a different target language. This task needs abstracting away from the source language-specific details, while keeping the overall functionality the same. In this work, we propose a novel and systematic approach for making such translation amenable to automation based on a framework we call program skeletons. A program skeleton retains the high-level structure of the source program by abstracting away and effectively summarizing lower-level concrete code fragments, which can be mechanically translated to the target programming language. A skeleton, by design, permits many different ways of filling in the concrete implementation for fragments, which can work in conjunction with existing data-driven code synthesizers. Most importantly, skeletons can conceptually enable sound decomposition, i.e., if each individual fragment is correctly translated, taken together with the mechanically translated skeleton, the final translated program is deemed to be correct as a whole. We present a prototype system called Skel embodying the idea of skeleton-based translation from Python to JavaScript. Our results show promising scalability compared to prior works. For 9 real-world Python programs, some with more than about 1k lines of code, 95% of their code fragments can be automatically translated, while about 5% require manual effort. All the final translations are correct with respect to whole-program test suites.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。