当Scheme 子集似乎更适合时,为什么C 是编译器语言?

发布于 2024-08-17 02:12:48 字数 426 浏览 3 评论 0原文

我刚刚在听 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 技术交流群。

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

发布评论

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

评论(7

动听の歌 2024-08-24 02:12:48

我不会费心去听 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.

浮萍、无处依 2024-08-24 02:12:48

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.

開玄 2024-08-24 02:12:48

原因之一是在不受支持的体系结构上引导编译器的问题。这通常需要存在一个适用于该架构的工作编译器,这通常意味着 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.

疯了 2024-08-24 02:12:48

这可能是多种因素的综合作用:

  1. C 编译器几乎适用于所有平台,这使得为新语言构建新编译器变得更加容易。
  2. 历史:C 是一种非常流行的语言,因此很多项目都使用 C 语言(无论项目是什么)是有道理的。
  3. 具体来说,Scheme 非常不受欢迎(与 C 相比)。

It's probably a combination of factors:

  1. C compilers are available for almost every platform, making it easier to build a new compiler for a new language.
  2. History: C is a very popular language, so it makes sense that a lot of projects are in C (no matter the project).
  3. Scheme, specifically, is very unpopular (compared to C).
忘羡 2024-08-24 02:12:48

如果我记得的话,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

苏大泽ㄣ 2024-08-24 02:12:48

如今许多编译器都是用 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.

分开我的手 2024-08-24 02:12:48

我认为与后端有很大关系。有人提到了 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.

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