编译成 C/C++ 源代码的编程语言?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6498850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programming languages that compile into C/C++ source?
提问by Jeff
I'm using CoffeeScriptto make JavaScript development easier. It's a language with clean syntax that compiles into JavaScript.
我正在使用CoffeeScript来简化JavaScript 开发。它是一种语法清晰的语言,可以编译成 JavaScript。
So, what are the established programming languages that compile into C/C++ source code, to simplify syntax and/or enhance functionality?
那么,编译成 C/C++ 源代码以简化语法和/或增强功能的既定编程语言是什么?
回答by M.Stoffregen
回答by Sean
Valaand Genieare 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.
Vala和Genie是使用 GObject 类型系统并编译为 C 代码的语言。我从未使用过它们,但它们看起来很有趣。GObject 是 GTK 使用的类型系统,但我相信它与 GTK 是可分离的。
回答by stusmith
GHC (the Glasgow Haskell Compiler)used to have an option (-fvia-c
) to compile to C.
GHC(格拉斯哥 Haskell 编译器)曾经有一个选项 ( -fvia-c
) 来编译为 C。
I believe that starting with v7 however, LLVM is used to generate native code instead of going via an external C compiler.
但是,我相信从 v7 开始,LLVM 用于生成本机代码,而不是通过外部 C 编译器。
回答by Vinicius Kamakura
Quoting Qtdocumentation:
引用Qt文档:
The Meta-Object Compiler, moc, is the program that handles Qt's C++ extensions. The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes. Among other things, meta-object code is required for the signals and slots mechanism, the run-time type information, and the dynamic property system. The C++ source file generated by moc must be compiled and linked with the implementation of the class.
元对象编译器 (moc) 是处理 Qt 的 C++ 扩展的程序。moc 工具读取 C++ 头文件。如果它找到一个或多个包含 Q_OBJECT 宏的类声明,它会生成一个 C++ 源文件,其中包含这些类的元对象代码。其中,信号和槽机制、运行时类型信息和动态属性系统需要元对象代码。moc 生成的 C++ 源文件必须编译并与类的实现链接。
So it's kind of C++ getting turned into C++, I'm not sure if it fits in what you are looking for.
所以它是一种 C++ 变成了 C++,我不确定它是否适合你正在寻找的东西。
回答by Jonathan Leffler
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.
编程语言 IBM Informix 4GL 经过多步转换为 C 代码,然后编译并链接到它自己的运行时库、ESQL/C(C 中的嵌入式 SQL)运行时库和系统的 C 库。
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
- executable
program.4gl
- 原始源代码program.4ec
- 带有嵌入式 ESQL/C 和扩展输入操作的 C 代码program.ec
- 带有嵌入式 ESQL/C 的 C 代码program.c
- 纯 C 代码program.o
- 目标代码program
- 可执行
The .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.
这个.4ec
阶段是一种历史偶然;最初,ESQL/C 编译器同时处理扩展输入操作和 ESQL/C,但是当扩展操作从 ESQL/C 编译器中删除时(当 ESQL/C 库和编译器被显着重写时),扩展输入操作是通过从原始 ESQL/C 编译器中雕刻出处理它的代码来处理的。
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.
相当多的人编写了代码生成器,它们从另一种语言编写 I4GL 源代码,或者在将密切相关的源代码提交给 I4GL 编译器之前将其预处理为 I4GL。
回答by sigjuice
Embeddable Common Lisp (ECL)can compile Common Lisp to C.
Embeddable Common Lisp (ECL)可以将 Common Lisp 编译为 C。
回答by Mikola
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)
我想你可以为 LLVM 编写一个 C 后端,然后你可以将几乎任何东西翻译成 C,但更深层次的问题是“为什么?” 今天没有任何工具可以做到这一点的原因是,如果你要编译成 C,为什么不一直以某种中间机器代码语言为目标呢?(例如,LLVM 或 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:
现在在过去,编译成 C 的想法更有道理,因为缺乏像样的 vm 语言,但今天没有太多好的理由去做。也就是说,您仍然可以找到许多项目,这些项目采用某些解释性语言并尝试将它们编译为 C/C++。例如,这是一个 python 到 C++ 的编译器:
回答by thkala
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.
也就是说,正如其他人所提到的,有很多语言有(或曾经在开发早期)生成 C 代码的后端,因为这消除了从语言实现中生成二进制代码所涉及的复杂性. 这绝不意味着(双关语意料之外)所述代码实际上是可读的——它只是比其编译形式更具可读性。
As for my contribution to the list, lexand yacc"programs" (if they can be considered that) are typically transformed into C code - a horrible, tangled mess of it, but C code nonetheless...
至于我对列表的贡献,lex和yacc“程序”(如果可以考虑的话)通常被转换为 C 代码 - 一个可怕的、混乱的混乱,但 C 代码仍然......