可运行的伪代码?

发布于 2024-07-09 04:16:34 字数 451 浏览 9 评论 0原文

我试图确定以下想法的现有技术:

1)用户用名为(insert_name_here)的语言输入一些代码;

2) 用户从众所周知的候选输出列表中选择目标语言(javascript、ruby、perl、python);

3)处理器将insert_name_here翻译成目标语言的可运行代码;

4) 然后,处理器使用基于所选语言的相关系统调用来运行代码。

这样做的原因是因为从 insert_name_here 到所有支持的目标语言的所有语言结构之间存在预先建立的 1 对 1 映射。

免责声明:这显然不会产生适合目标语言的“优雅”代码。它只是进行可运行的基本翻译。目的是让开发人员能够快速获得以及用几种不同语言实现算法的肮脏实现,用于那些不想重新发明轮子,但出于某种原因需要在特定项目中使用特定语言的情况。)

这是否已经存在?

I am attempting to determine prior art for the following idea:

1) user types in some code in a language called (insert_name_here);

2) user chooses a destination language from a list of well-known output candidates (javascript, ruby, perl, python);

3) the processor translates insert_name_here into runnable code in destination language;

4) the processor then runs the code using the relevant system call based on the chosen language

The reason this works is because there is a pre-established 1 to 1 mapping between all language constructs from insert_name_here to all supported destination languages.

(Disclaimer: This obviously does not produce "elegant" code that is well-tailored to the destination language. It simply does a rudimentary translation that is runnable. The purpose is to allow developers to get a quick-and-dirty implementation of algorithms in several different languages for those cases where they do not feel like re-inventing the wheel, but are required for whatever reason to work with a specific language on a specific project.)

Does this already exist?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

乖乖 2024-07-16 04:16:34

.NET CLR 的设计使得 C++.Net、C#.Net 和 VB.Net 都编译为相同的机器语言,并且您可以将该 CLI“反编译”回其中任何一种语言。

所以是的,我想说它已经存在,尽管不完全像你所描述的那样。

The .NET CLR is designed such that C++.Net, C#.Net, and VB.Net all compile to the same machine language, and you can "decompile" that CLI back in to any one of those languages.

So yes, I would say it already exists though not exactly as you describe.

怪异←思 2024-07-16 04:16:34

有适用于不同语言的转换器。 您将遇到的问题是与库打交道。 虽然语言语句之间的映射可能很容易,但查找库函数之间的映射将非常困难。

我不太确定这种类型的代码生成器有多大用处。 为什么你想用一种语言编写一些东西,然后立即将其转换为其他语言? 我可以看到第四代语言将图表或模型转换为代码的基本原理,但我并没有真正看到你的努力的意义。

There are converters available for different languages. The problem you are going to have is dealing with libraries. While mapping between language statements might be easy, finding mappings between library functions will be very difficult.

I'm not really sure how useful that type of code generator would be. Why would you want to write something in one language and then immediately convert it to something else? I can see the rationale for 4th Gen languages that convert diagrams or models into code but I don't really see the point of your effort.

缺⑴份安定 2024-07-16 04:16:34

是的,将程序从一种表示形式转换为另一种表示形式的程序确实存在。 它被称为“编译器”。

至于你的问题是否总是可能的:只要你的目标语言至少与源语言一样强大,那么就有可能。 因此,如果您的目标语言是图灵完备的,那么它总是是可能的,因为没有任何语言比图灵完备的语言更强大。

然而,并不需要存在愚蠢的 1:1 映射。

例如:将 CIL 字节码编译为 JavaScript 源代码的 Microsoft Volta 编译器存在一个问题:.NET 有线程,而 JavaScript 没有。 但是您可以通过延续来实现线程。 嗯,JavaScript 也没有延续,但您可以在例外情况下实现延续。 因此,Volta将CIL转换为CPS,然后在例外情况下实现CPS。 (较新版本的 JavaScript 具有生成器形式的半协程;这些也可以使用,但 Volta 旨在跨广泛的 JavaScript 版本工作,显然包括 Internet Explorer 中的 JScript。)

Yes, a program that transform a program from one representation to another does exist. It's called a "compiler".

And as to your question whether that is always possible: as long as your target language is at least as powerful as the source language, then it is possible. So, if your target language is Turing-complete, then it is always possible, because there can be no language that is more powerful than a Turing-complete language.

However, there does not need to be a dumb 1:1 mapping.

For example: the Microsoft Volta compiler which compiles CIL bytecode to JavaScript sourcecode has a problem: .NET has threads, JavaScript doesn't. But you can implement threads with continuations. Well, JavaScript doesn't have continuations either, but you can implement continuations with exceptions. So, Volta transforms the CIL to CPS and then implements CPS with exceptions. (Newer versions of JavaScript have semi-coroutines in the form of generators; those could also be used, but Volta is intended to work across a wide range of JavaScript versions, including obviously JScript in Internet Explorer.)

北斗星光 2024-07-16 04:16:34

这似乎有点奇怪。 如果您以最常见的形式使用术语“现有技术”,那么您正在讨论一个可能获得专利的想法。 如果这种情况,您将:

1/ 发布了该想法,开始进行专利申请 - 我假设(也许是错误的)您位于美国 其他司法管辖区可能有其他规则。

2/ 告诉整个地球你的想法,这意味着尝试申请专利几乎毫无用处,除非你行动得非常快。

如果您没有考虑为此申请专利,而只是在外行意义上使用“现有技术”一词,我深表歉意。 我工作的公司非常重视专利,并且非常详细地向我们灌输了我们在申请前可以对信息做什么的信息。

话虽如此,可申请专利的想法必须新颖、有用且非显而易见。 我认为你的想法不会传递第三个,因为你正在描述一个语言翻译器,它拥有许多 pascal-to-c 和 fortran-to-c 转换器的现有技术。

一线希望是你的想法能够生成多种输出语言中的一种(p2c 和 f2c 不这样做),但我认为即使这样也可以被交叉编译器(例如 gcc)之类的东西所覆盖,这些编译器将将源代码转换为许多不同的对象语言之一。

IBM 有一款名为 Visual Age Generator 的产品,您可以在其中使用一种(专有)语言进行编码,然后将其转换为 COBOL/C/Java/其他语言,以便在从 PC 到大型 System z 大型机的不同目标平台上运行,因此这是您的第一个问题(考虑为世界上最大的专利持有者 IBM 已经在使用的想法申请专利)。

This seems a little bizarre. If you're using the term "prior art" in its most common form, you're discussing a potentially patentable idea. If that is the case, you have:

1/ Published the idea, starting the clock running on patent filing - I'm assuming, perhaps incorrectly, that you're based in the U.S. Other jurisdictions may have other rules.

2/ Told the entire planet your idea, which means it's pretty much useless to try and patent it, unless you act very fast.

If you're not thinking about patenting this and were just using the term "prior art" in a laypersons sense, I apologize. I work for a company that takes patents very seriously and it's drilled into us, in great detail, what we're allowed to do with information before filing.

Having said that, patentable ideas must be novel, useful and non-obvious. I would think that your idea would not pass on the third of these since you're describing a language translator which would have the prior art of the many pascal-to-c and fortran-to-c converters out there.

The one glimmer of hope would be the ability of your idea to generate one of multiple output languages (which p2c and f2c don't do) but I think even that would be covered by the likes of cross compilers (such as gcc) which turn source into one of many different object languages.

IBM has a product called Visual Age Generator in which you code in one (proprietary) language and it's converted into COBOL/C/Java/others to run on different target platforms from PCs to the big honkin' System z mainframes, so there's your first problem (thinking about patenting an idea that IBM, the biggest patenter in the world, is already using).

贪了杯 2024-07-16 04:16:34

有很多。 p2c、f2c 以及 C++ 和 Objective C 的原始实现立即给我留下了深刻的印象。 除此之外,很难将您所描述的内容与任何编译器区分开来,尤其是对于我们这些老家伙来说,无论如何,他们的编译器都会生成用于中间重新预设的 ASM 代码。

Tons of them. p2c, f2c, and the original implementation s of C++ and Objective C strike me immediately. Beyond that, it's kind of hard to distinguish what you're describing from any compiler, especially for us old guys whose compilers generated ASM code for an intermediate represetation anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文