arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2301.11220cs.PLcs.SE
收藏

用户可自定义的脚本语言翻译

User-Customizable Transpilation of Scripting Languages

Bo Wang, Aashish Kolluri, Ivica Nikolić, Teodora Baluta, Prateek Saxena

摘要:

转译器将代码从一种程序设计语言转换为另一种。转译器的许多实际用途要求用户能够引导或定制从给定输入程序产生的程序。这种可定制性对于满足许多特定于应用程序的目标非常重要,例如确保性能,可读性,可维护性,兼容性等。传统的转译器是确定性规则驱动的系统,通常不提供每个用户和每个程序的可定制性。基于神经网络的转译器的最新进展为用户提供了一些可定制性,例如通过交互式提示,但是它们仍然难以精确地控制期望输出的产生。传统和神经转译都存在“最后一英里”问题:它们平均产生正确的代码,即,我们提出了一种新的编译方法,提供了细粒度的可定制性和可重用性的编译规则创建的其他人,而不负担用户理解的全局语义给定的源程序。我们的方法主要是自动和增量的,即,根据用户的指导,逐段构造翻译给定程序所需的翻译规则。我们实现了一个名为DuoGlot的工具,它将Python转换为JavaScript程序,并在流行的GeeksForGeeks基准上对其进行评估。DuoGlot实现了90%的翻译准确率,因此它优于所有现有的翻译器,同时它生成可读的代码。我们在另外两个基准上评估了DuoGlot,其中包含更具挑战性和更长的程序,并同样观察到准确性提高。

英文摘要:

A transpiler converts code from one programming language to another. Many practical uses of transpilers require the user to be able to guide or customize the program produced from a given input program. This customizability is important for satisfying many application-specific goals for the produced code such as ensuring performance, readability, maintainability, compatibility, and so on. Conventional transpilers are deterministic rule-driven systems often written without offering customizability per user and per program. Recent advances in transpilers based on neural networks offer some customizability to users, e.g. through interactive prompts, but they are still difficult to precisely control the production of a desired output. Both conventional and neural transpilation also suffer from the "last mile" problem: they produce correct code on average, i.e., on most parts of a given program, but not necessarily for all parts of it. We propose a new transpilation approach that offers fine-grained customizability and reusability of transpilation rules created by others, without burdening the user to understand the global semantics of the given source program. Our approach is mostly automatic and incremental, i.e., constructs translation rules needed to transpile the given program as per the user's guidance piece-by-piece. We implement the transpiler as a tool called DuoGlot, which translates Python to Javascript programs, and evaluate it on the popular GeeksForGeeks benchmarks. DuoGlot achieves 90% translation accuracy and so it outperforms all existing translators, while it produces readable code. We evaluate DuoGlot on two additional benchmarks, containing more challenging and longer programs, and similarly observe improved accuracy.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑