编译为 C/C++ 的编程语言来源?
我使用 CoffeeScript 来简化 JavaScript 开发。它是一种语法清晰的语言,可以编译成 JavaScript。
那么,有哪些已建立的编程语言可以编译为 C/C++ 源代码,以简化语法和/或增强功能?
I'm using CoffeeScript to make JavaScript development easier. It's a language with clean syntax that compiles into JavaScript.
So, what are the established programming languages that compile into C/C++ source code, to simplify syntax and/or enhance functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
Vala 和 Genie 是以下语言:使用 GObject 类型系统并编译为 C 代码。我从未使用过它们,但它们看起来很有趣。 GObject 是 GTK 使用的类型系统,但我相信它与 GTK 是分开的。
Vala and Genie are languages that use the GObject type system and compile to C code. I've never used them but they look interesting. GObject is the type system used by GTK but I believe it's separable from GTK.
GHC(Glasgow Haskell 编译器) 曾经有一个选项 (
-fvia-c
) 来编译为 C。我相信从 v7 开始,LLVM 用于生成本机代码而不是通过外部 C 编译器。
GHC (the Glasgow Haskell Compiler) used to have an option (
-fvia-c
) to compile to C.I believe that starting with v7 however, LLVM is used to generate native code instead of going via an external C compiler.
OOC 很新,但相当不错。
OOC is very new but quite nice.
HipHop 可以将 PHP 程序转换为 C++。
There's HipHop, which transforms PHP programs to C++.
引用 Qt 文档:
所以这有点像 C++ 变成了 C++,我不确定它是否符合您的需求。
Quoting Qt documentation:
So it's kind of C++ getting turned into C++, I'm not sure if it fits in what you are looking for.
编程语言 IBM Informix 4GL 经过多步转换为 C 代码,然后对其自身的运行时库、ESQL/C(C 中的嵌入式 SQL)运行时库以及系统的 C 库进行编译和链接。
program.4gl
- 原始源代码program.4ec
- 带有嵌入式 ESQL/C 和扩展输入操作的 C 代码program.ec
- 带有嵌入式 ESQL/C 和扩展输入操作的 C 代码嵌入式 ESQL/Cprogram.c
- 纯 C 代码program.o
- 目标代码program
- 可执行文件.4ec
阶段是一种历史偶然;最初,ESQL/C 编译器同时处理扩展输入操作和 ESQL/C,但是当从 ESQL/C 编译器中删除扩展操作时(当 ESQL/C 库和编译器被显着重写时),扩展输入操作通过从原始 ESQL/C 编译器中提取处理该问题的代码来处理。有相当多的人编写了代码生成器,可以从另一种语言编写 I4GL 源代码,或者在将密切相关的源代码提交给 I4GL 编译器之前将其预处理为 I4GL。
The programming language IBM Informix 4GL goes through a multi-step transformation to C code, which is then compiled and linked with its own runtime library, the ESQL/C (Embedded SQL in C) runtime libraries, and the system's C libraries.
program.4gl
- original source codeprogram.4ec
- C code with embedded ESQL/C and extended input operationsprogram.ec
- C code with embedded ESQL/Cprogram.c
- pure C codeprogram.o
- object codeprogram
- executableThe
.4ec
phase is a sort of historical accident; originally, the ESQL/C compiler handled both the extended input operations and the ESQL/C, but when the extended operations were removed from the ESQL/C compiler (when the ESQL/C library and compiler was significantly rewritten), the extended input operations were handled by carving out the code that handled that from the original ESQL/C compiler.A fair number of people have written code generators which write I4GL source from another language, or which preprocess a closely related source code into I4GL before it is submitted to the I4GL compiler.
Embeddable Common Lisp (ECL) 可以将 Common Lisp 编译为 C。
Embeddable Common Lisp (ECL) can compile Common Lisp to C.
我想你可以为 LLVM 编写一个 C 后端,然后你可以将几乎任何东西转换为 C,但更深层次的问题是“为什么?”今天没有任何工具可以做到这一点的原因是,如果您要编译为 C,为什么不一路走下去并以某种中间机器代码语言为目标呢? (例如,LLVM 或 JVM)
现在,在过去,编译为 C 的想法更有道理,因为缺乏像样的 vm 语言,但今天没有太多充分的理由这样做。也就是说,您仍然可以找到大量采用某些解释语言并尝试将它们编译为 C/C++ 的项目。例如,以下是一个 Python 到 C++ 的编译器:
http://shed-skin.blogspot.com/
I suppose you could write a C backend for LLVM, then you could translate pretty much anything down to C, but the deeper question would be "why?" The reason that there aren't any tools that do this today is that if you are going to compile down to C, why not go all the way and target some intermediate machine code language instead? (For example, LLVM or the JVM)
Now in the older days, the idea of compiling down to C was a bit more defensible, since there was a lack of decent vm languages, but today there are not too many good reasons to do it. That said, you can still find plenty of projects around which take certain interpreted languages and try to compile them down to C/C++. For example, here is a python to C++ compiler:
http://shed-skin.blogspot.com/
有人可能会说,由于大多数主要编程语言都是图灵完备,因此它们实际上是等效的并且编写的程序它们之间可以互相翻译。
也就是说,正如其他人所提到的,有相当多的语言有(或在开发早期曾经有)生成 C 代码的后端,因为这消除了语言实现中二进制代码生成所涉及的复杂性。这绝不意味着(双关语无意)所述代码实际上是可读的 - 它只是比其编译形式更具可读性。
至于我对该列表的贡献,lex 和 yacc “程序”(如果它们可以被认为是这样的话)通常被转换成 C 代码 - 一个可怕的、混乱的混乱,但仍然是 C 代码。 ..
One could argue that since most major programming languages are Turing-complete, they are actually equivalent and programs written in them can be translated into each other.
That said, as other people have mentioned, there are quite a few languages for which there are (or used to be, early in their development) backends that produce C code, since that removed the complexities involved in binary code generation from the language implementation. That does not by any means mean (pun unintended) that said code was actually readable - it was just more readable than its compiled form.
As for my contribution to the list, lex and yacc "programs" (if they can be considered that) are typically transformed into C code - a horrible, tangled mess of it, but C code nonetheless...
我听说 clang 可以将 C++ 编译为 C。不过,我怀疑这会“简化”任何东西。
I hear that clang can compile C++ into C. I doubt that would "simplify" anything, though.
Oracle 的 PRO*C/C++ 是一种嵌入式 SQL 语言。它允许在 C/C++ 中包含 SQL 语句,该语句由预编译器处理,该预编译器用对所需 C/C++ SQL 库的函数调用替换嵌入式 SQL 语句。预编译器的输出是标准 C/C++,然后可以将其编译为可执行文件。
http://en.wikipedia.org/wiki/Pro*C
http://download.oracle.com/docs/cd /B19306_01/appdev.102/b14407/toc.htm
Oracle's PRO*C/C++ is an embedded SQL language. It allows the inclusion of SQL statements in C/C++ which is processed by a precompiler that replaces the embedded SQL statements with function calls to the needed C/C++ SQL libraries. The output from the precompiler is standard C/C++ which can then be compiled to an executable.
http://en.wikipedia.org/wiki/Pro*C
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14407/toc.htm
Matlab(嵌入式Matlab)的子集可以编译为C。您需要嵌入式编码器工具箱。
A subset of Matlab (Embedded Matlab) can be compiled to C. You need the embedded coder toolbox.
大多数语言都可以用来生成 C 代码,但这实际上取决于您想要做什么。您真的希望能够阅读代码吗?您只是想创建 Windows 应用程序吗?
如果您正在寻找一种易于学习的通用语言,Python 始终是一个不错的选择,它可以完成 C/C++ 可以做的所有事情。
Most languages can be used to generate C code, but it really depends what you're trying to do. Do you actually want to be able to read the code? Are you just trying to create Windows applications?
If you're looking for a universally useful language that's easy to learn, Python is always a good choice, and it can do everything that C/C++ can.
语言 Haxe 可以输出到 C++、C#、Java、JavaScript、Python(实验)、PHP、Flash 和 NekoVM。
The language Haxe can output to C++, C#, Java, JavaScript, Python(experimental), PHP, Flash and NekoVM.