有哪些工具可以将程序从A平台迁移到B平台
作为一个宠物项目,我正在考虑编写一个程序,将用 A 语言编写的应用程序迁移到 B 语言中。 A 和 B 是面向对象的语言。 我认为这是一项非常艰巨的任务:映射相似的语言结构是可行的,但映射库概念将是一项非常漫长的任务。
我想知道要使用什么工具,我知道这与编译有关,但我有点害怕使用 Lex 和 Yacc 以及所有这些东西。 我正在考虑使用 Eclipse 建模框架,它可以帮助我以可读的形式编写(应用程序代码的)模型转换。 但首先我必须编写解析器来创建模型(并根据语言语法创建元模型)。
是否存在可以让我的任务变得更轻松的工具?
As a pet project, I was thinking about writing a program to migrate applications written in a language A into a language B.
A and B would be object-oriented languages. I suppose it is a very hard task : mapping language constructs that are alike is doable, but mapping libraries concepts will be a very long task.
I was wondering what tools to use, I know this has to do with compilation, but I'm a bit afraid to use Lex and Yacc and all that stuff.
I was thinking of maybe using the Eclipse Modeling Framework, which would help me write models (of application code) transformations in a readable form.
But first I would have to write parsers for creating the models (and also create the metamodel from the language grammar).
Are there tools that exist that would make my task easier?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用特殊的转换工具/语言来实现 TXL 或 Stratego/XT。
您也可以看看并轻松尝试 Java 到 Python以及Java 到 Tcl 迁移我用 TXL 制作的项目。
您关于映射库概念是正确的。 这是一项相当艰巨且漫长的任务。 这里有两种方法:
您将选择的方法取决于您的目标和可用的时间/资源。 此外,在许多情况下,您不会进行涵盖所有可能情况的一般 A->B 迁移,您只需要转换一些项目/库/等。 所以你会在你的特定情况下看到如何更好地处理类/库。
You can use special transformation tools/languages for that TXL or Stratego/XT.
Also you can have a look and easily try Java to Python and Java to Tcl migrating projects made by me with TXL.
You are right about mapping library concepts. It is rather hard and long task. There are two ways here:
The approach you will choose depends on your goals and time/resources available. Also in many cases you wont be doing a general A->B migration which will cover all possible cases, you will need just to convert some project/library/etc. so you will see in your particular cases what is better to do with classes/libraries.
我认为这几乎是不可能的困难,尤其是作为一个个人项目。 但是,如果您打算这样做,请不要尝试提出通用解决方案,从而使自己的生活变得更加困难。 选择两种特定的现实编程语言,并研究它们之间转换的可能性。 我想你会对这将暴露的问题和问题的数量感到震惊。
I think this is almost impossibly hard, especially as a personal project. But if you are going to do it, don't make life even more difficult for yourself by trying to come up with a general solution. Choose two specific real-life programming languages ind investigate the possibities of converting between them. I think you will be shocked by the number of problems and issues this will expose.
对于A和B的某些组合,有一些直接迁移的工具。
针对不同语言和平台,有多种逆向工程和代码生成工具。 很少有逆向工程工具能够捕获源语言的所有语义,而且 UML 的语义也没有很好地定义(因为它被设计为映射到不同的实现语言,它本身并没有为其定义完整的执行模型)行为表示),因此您不太可能能够在工具之间进行逆向工程和生成代码。 您可能会找到一种工具,可以为您的 A 语言和 B 语言进行完整的逆向工程和完整的代码生成,因此也许能够有所收获。
一般来说,您不会在不同平台上使用相同的习惯用法,因此您更有可能获得在 B 上模拟 A 代码的东西,而不是对应于本机 B 解决方案的东西。
There are some tools for direct migration for some combinations of A and B.
There are a variety of reverse engineering and code generation tools for different languages and platforms. It's fairly rare to see reverse engineering tools which capture all the semantics of the source language, and the semantics of UML are not well defined ( since it's designed to map to different implementation languages, it itself doesn't define a complete execution model for its behavioural representations ), so you're unlikely to be able to reverse engineer and generate code between tools. You may find one tool that does full reverse engineering and full code generation for your A and B languages, and so may be able to get somewhere.
In general you don't use the same idioms on different platforms, so you're more likely to get something which emulates A code on B rather than something which corresponds to a native B solution.
如果您想使用 Java 作为源语言(您尝试转换的语言),那么您可以使用 Checkstyle AST(它用于编写规则)。 它为您提供了源代码中完成的每个操作的树结构。 这比编写自己的 Paser 或使用正则表达式要容易得多。
您可以从 checkstyle-4.4.jar 运行 com.puppycrawl.tools.checkstyle.gui.Main 来启动解析 Java 源代码的 Swing GUI。
If you want to use Java as the source language(that language you try to convert) than you might use Checkstyle AST(its used to write Rules). It gives you tree structure with every operation done in the source code. This will be much more easier than writing your own paser or using regex.
You can run com.puppycrawl.tools.checkstyle.gui.Main from checkstyle-4.4.jar to launch Swing GUI that parse Java Source Code.
根据您的评论
Google Web Toolkit 可能值得一看。
Based on your comment
Google Web Toolkit might be worth a look.
请参阅此答案:我可以在代码上强制执行哪些类型的模式翻译成另一种编程语言更容易吗?
See this answer: What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?