当Scheme 子集似乎更适合时,为什么C 是编译器语言?
我刚刚在听 Software Engineering Radio 的第 57 集 (转录:http://www.se-radio.net/transcript-57 -编译时元编程) 我只用了 40 分钟,但我想知道为什么 C 是编译器的语言 - 当一个方案子集似乎更适合时? (或其他一些 HLL) (排除不想重写 gcc 的明显原因)
PS 最初在 LtU http:// lambda-the-ultimate.org/node/3754
I was just listening to episode 57 of Software Engineering Radio
(TRANSCRIPT: http://www.se-radio.net/transcript-57-compiletime-metaprogramming )
I'm only 40 minutes in, but I'm wondering why C is the language of compilers- when a Scheme subset would seem to be a better fit? (or some other HLL)
(excluding the obvious reason of not wanting to rewrite gcc)
PS originally posted this at LtU http://lambda-the-ultimate.org/node/3754
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我不会费心去听 40 分钟的广播,也许是为了更彻底地理解你的问题,但我的说法恰恰相反。只有少数编译器是用 C 编写的。我的印象是(至少在适当的情况下),大多数编译器都是用它们要编译的语言实现的。
I won't bother to listen to 40 minutes of radio to perhaps understand your question more thoroughly, but I would claim the exact opposite. Only a minority of compilers are written in C. I rather have the impression that (at least where appropriate), most compilers are implemented in the language they are meant to compile.
C 不一定是编译器的语言,但它确实有一些优点。 C 几乎可以在所有平台上使用,这使得移植和引导编译器变得很容易。 C 更接近硬件,可以实现许多其他语言难以实现的优化。用 C 编写的编译器很容易与其他语言、库和系统共存,因为它们大多数都提供 C 接口。对于其他人来说,扩展编译器也很容易,因为 C 是系统程序员的世界语。
C need not be the language for compilers, but it does have some advantages. C is available on almost all platforms and that makes it easy to port and bootstrap the compiler. C is closer to the hardware and makes possible many optimizations that will be difficult to achieve in other languages. It is easy for a compiler written in C to co-exist with other languages, libraries and systems as most of them provide a C interface. It is also easy for others to extend the compiler as C is the Esperanto of system programmers.
原因之一是在不受支持的体系结构上引导编译器的问题。这通常需要存在一个适用于该架构的工作编译器,这通常意味着 C。我记得尝试从源代码编译 MIT-scheme,并且非常生气,因为它需要先安装 MIT-scheme,然后才能构建 MIT-方案。
顺便说一句,我不确定我是否同意你的前提... C 无疑似乎是最广泛部署的语言,但其他语言编译器(例如 MIT-scheme)通常是用这些语言实现的。
Well, one reason will be the issue of bootstrapping the compiler on unsupported architectures. That will usually require the existence of a working compiler for that architecture, which generally means C. I remember trying to compile MIT-scheme from source, and getting really pissed off that it required MIT-scheme to be installed before I could build MIT-scheme.
Incidentally, I'm not sure I agree with your premise... C certainly seems to be the most widely deployed language, but other language compilers (e.g. MIT-scheme) are often implemented in those languages.
这可能是多种因素的综合作用:
It's probably a combination of factors:
如果我记得的话,C 有 Flex 和 Yacc ,它们有助于实现编译器的前端(解析器和词法分析器)对,他们的输出仅限于 c 代码
C has Flex and Yacc which help with implementing the Frontend (parser and lexer) of a compiler, if I remember right their output is limited to c code
如今许多编译器都是用 C 以外的语言编写的(例如Scheme)。为了使它们可移植,他们最初生成 C 代码作为目标语言。
Many compilers today are written in languages other than C (such as Scheme). To make them portable they initially generate C code as a target language.
我认为与后端有很大关系。有人提到了 Flex 和 Yacc,但还有 GCC 和 LLVM 可以帮助您完成许多其他重要的事情,例如优化。
I think a lot has to do with backends. Someone mentioned Flex and Yacc, but there's also GCC and LLVM that will help you with a lot of other important stuff, like optimizations.