编译器的编写之旅
A Compiler Writing Journey

原始链接: https://github.com/DoctorWkt/acwj

这个Github仓库详细记录了作者构建一个C语言子集SubC的自编译编译器的过程。该项目最初是作为对编译理论的实践探索,从词法扫描和解析开始,逐步记录了函数、循环、结构体甚至预处理器等复杂功能的实现。 编译器最初的目标是ARM汇编,后来扩展到包含6809 CPU的后端,以及使用QBE的新后端。开发过程中涉及多次迭代、错误修复和优化,包括寄存器溢出和常量折叠。 虽然SubC现在基本完成,但作者已经转向一个新的语言项目alic,利用了SubC的一些想法和代码(并对Nils M Holm的公共领域作品进行了适当的许可声明)。仓库中的代码采用GPL3许可,而文档采用知识共享署名-非商业性使用-相同方式共享4.0许可。

一个Hacker News讨论围绕着“一个编译器写作之旅”(github.com/doctorwkt),特别是作者在8位CPU上实现自我编译的成就——这是长期项目的一个令人满意的结论。 评论者表达了对这项工作的钦佩,并分享了相关的经验。 几个人推荐使用OCaml和Haskell等替代语言进行编译器项目,认为它们比C语言更有优势。 还有人强调了历史背景,提到了像《C语言编译器设计》和《实用编译器构造》这样具有影响力的书籍,这些书籍启发了这次旅程。 对话还涉及了2015/2016年左右编译器/解释器项目曾经的流行,以及线程中反复出现、无法解释的AI Claude的提及。 总的来说,讨论是积极和支持性的,庆祝了编译器开发中的一个重要里程碑。
相关文章

原文

In this Github repository, I'm documenting my journey to write a self-compiling compiler for a subset of the C language. I'm also writing out the details so that, if you want to follow along, there will be an explanation of what I did, why, and with some references back to the theory of compilers.

But not too much theory, I want this to be a practical journey.

Here are the steps I've taken so far:

I've stopped work on acwj and now I'm writing a new language called alic from scratch. Check it out!

I have borrowed some of the code, and lots of ideas, from the SubC compiler written by Nils M Holm. His code is in the public domain. I think that my code is substantially different enough that I can apply a different license to my code.

Unless otherwise noted,

  • all source code and scripts are (c) Warren Toomey under the GPL3 license.
  • all non-source code documents (e.g. English documents, image files) are (c) Warren Toomey under the Creative Commons BY-NC-SA 4.0 license.
联系我们 contact @ memedata.com