C语言 第一个 C 编译器是如何编写的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18125490/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:06:34  来源:igfitidea点击:

How was the first C compiler written?

cassemblycompiler-construction

提问by Jaskaran S.P

Is it true that the first C compiler was written in C itself? Then, how was it executed and compiled? Or, was this compiler written in assembly language?

第一个 C 编译器是用 C 本身编写的,这是真的吗?那么,它是如何执行和编译的呢?或者,这个编译器是用汇编语言写的吗?

回答by Hans Passant

It is described pretty well in Dennis Ritchie's writeupof the C language history.

Dennis Ritchie在 C 语言历史的文章中对此进行了很好的描述。

Giving just a summary of what he wrote there, use his article for the finer details. C started with the BCPL language, Ken Thomson had access to a compiler for it that ran on their General Electrics 635 main frame. Unhappy with the language, Thomson used BCPL to write a compiler for the B language, an evolutionary step beyond BCPL that removed some of the technical problems in BCPL.

仅给出他在那里写的内容的摘要,使用他的文章了解更详细的信息。C 从 BCPL 语言开始,Ken Thomson 可以访问在他们的通用电气 635 主机上运行的编译器。对语言不满意,Thomson 使用 BCPL 为 B 语言编写了一个编译器,这是超越 BCPL 的进化步骤,消除了 BCPL 中的一些技术问题。

They used B to create programs on their PDP-7 minicomputer, although most of them were little more than toy programs, the machine had very restricted hardware capabilities. One important step taken by Thomson was to rewrite the B compiler in B itself. A common bootstrapping step.

他们使用 B 在他们的 PDP-7 小型机上创建程序,虽然其中大多数只是玩具程序,但机器的硬件功能非常有限。Thomson 采取的一个重要步骤是在 B 本身中重写 B 编译器。一个常见的引导步骤。

That compiler was then gradually tweaked, through a short-lived intermediary step called NB (New B) to start resembling C. The PDP-11 minicomputer was instrumental in that step, giving them enough room to improve the language and compiler.

然后逐渐调整编译器,通过称为 NB(新 B)的短暂中间步骤开始类似于 C。 PDP-11 小型机在这一步中发挥了重要作用,为他们提供了足够的空间来改进语言和编译器。

回答by Belkacem REBBOUH

The first C compiler wasn't written in C, usually when writing a compiler we use either assembly language, or another programming language, and it's common that after first compilation, the compiler is rewritten in it's native language.

第一个 C 编译器不是用 C 编写的,通常在编写编译器时我们使用汇编语言或其他编程语言,而且通常在第一次编译后,编译器会用它的本地语言重写。

There's a lot of programming languages that have been written in C then rewritten in their native language : Java for example, Ada ...

有很多编程语言是用 C 编写的,然后用它们的母语重写:例如 Java,Ada ...

回答by egyik

Reading Dennis Ritchie's note on primevalCindicates that, rather like the chicken and the egg, C evolved from a precursor language along with its own compilervia bootstrapping. The speciation timescales were quicker than for Gallus gallus domesticus.

阅读丹尼斯·里奇 (Dennis Ritchie) 关于原始C的笔记表明,就像先有鸡和先有蛋一样,C通过引导从前驱语言及其自己的编译器演变而来。物种形成时间尺度比 Gallus gallusdomesticus 快。

One can even see the compiler source code caught in the midst of the evolutionary turmoil. The note links to two snapshots of it restored from tape backups. This code has also been placed on github.These snapshots constitute intermediate fossils, years before K&R syntax. Dennis' description of one of the tapes shows it is a freeze-frame of structs being bootstrapped:

甚至可以看到编译器源代码陷入了进化的混乱之中。该笔记链接到从磁带备份恢复的两个快照。这段代码也放到了github上。这些快照构成了中间化石,比 K&R 语法早了几年。Dennis 对其中一个磁带的描述表明,它是一个自举结构的冻结帧:

"prestruct-c" is a copy of the compiler just before I started changing it to use structures itself.

“prestruct-c”是编译器的副本,就在我开始将其更改为使用结构本身之前。

In other words the compiler had been augmented to supportstructs but didn't yet usethem. A good time to make a tape backup...

换句话说,编译器已被扩充以支持结构,但尚未使用它们。进行磁带备份的好时机...