编程与软件工程compilers.iecc.com编辑精选
让我们来写一个编译器
Let’s Build a Compiler (1995)
2010 — 2023,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 Jack Crenshaw 的经典编译器构建教程系列,从零开始手把手演示如何写出一个能工作的编译器,涉及表达式解析、代码生成等基础环节。它带有明显的年代痕迹:示例语言是 Pascal,目标后端是 68000 汇编,而不是一本系统性的现代理论教材。
为什么经久不衰:它把编译器构造拆成可跟着做的步骤,几乎不依赖厚重理论;尽管后端过时,今天仍是理解“编译器到底怎么跑起来”的最佳入门之一。
HN 评论精选
最佳手把手入门,读完可转向龙书和 Appel 等理论/后端教材。
这个系列是编译器构造最好的入门之一。它没有覆盖所有内容,而且已经 25 年了,但它是我知道的唯一会手把手带你从零构建一个能工作的编译器的指南。如果你从没构建过编译器,我想不出更好的起点。之后若对理论和进阶主题感兴趣,我推荐 Aho、Sethi、Ullman 的《Compilers: Principles, Techniques, and Tools》(龙书,覆盖很多前端理论),再读 Appel 的《Modern Compiler Construction in ML》(覆盖更多进阶主题和后端内容)。
groovy2shoes查看英文原文
This series is one of the best introductions to compiler construction. It doesn't cover everything and it's 25 years old now, but it is the only guide I know of that will hold your hand as you build a working compiler from scratch. If you have never built a compiler before, I cannot think of a better place to start. Afterward, if you're curious about theory and advanced topics, I recommend heading to Compilers: Principles, Techniques, and Tools by Aho, Sethi, and Ullman (which covers a lot of theory associated with front-ends) then proceeding to Modern Compiler Construction in ML by Appel (which covers some more advanced topics and back-end stuff). Then you can continue reading about more specific/advanced topics if you like.
推荐现代理论课程,特色是 parsing with derivatives、Racket 和 Python→C 项目。
如果你在找现代编译器课程——包括这些技术为何有效的理论——我强烈推荐 Matt Might 的课程,所有讲义、幻灯片和代码都在网上。我今年春天旁听了他的“Compilers”:他现场写了一个用导数解析的解析器,文法有歧义时返回所有可能的解析树(用 yacc 等工具很难做到);代码都用 Racket Scheme。期末项目是一个能工作的 Python→C 翻译器。
sigil查看英文原文
If you're looking for a modern compilers class -- including the theory of why this stuff works -- I highly recommend Matt Might's [0]. All of the notes, slides, and code are online. I audited Might's "Compilers" this spring. He live-coded a parser that parsed with derivatives, returning all possible parse trees whenever there were ambiguities in the grammar. [1] (Try getting that from yacc, or basically any other tool in existence right now.) All of his coding was done in Racket scheme. At the beginning he told us we could use whatever for the projects, but doing certain things in C++ / Java / Python / some imperative language was "like bringing a knife to a gun-fight." The final project was a working Python -> C translator. Really badass class. [0] http://matt.might.net/teaching/compilers/spring-2013/ [1] http://matt.might.net/articles/parsing-with-derivatives/
作者当年用 Turbo Pascal 跟学;Pascal 适合当伪代码,且有 Ruby 重写和更多资源。
我在 90 年代初跟着这个系列学过,过程很愉快。当时我的首选语言是 Turbo Pascal,这很有帮助;现在可能没那么有用,不过 Pascal 仍是相当好的伪代码。Vidar Hokstad 多年来一直在写 Ruby 版本系列,另外还有很多其他资源。
petercooper查看英文原文
I followed this in the early 90s and had a lovely time. It helped that Turbo Pascal was my language of choice though and might not be quite so helpful now although Pascal is a pretty good pseudocode.. It's not the same but Vidar Hokstad has been writing a series for several years now in Ruby: http://www.hokstad.com/compiler/ .. and other resources aplenty: http://stackoverflow.com/a/1672/3951
询问是否有 AMD64 后端版本或精简指令集入门,以弥补原教程后端过时的问题。
我喜欢这个系列!有人知道是否有人做过输出 AMD64 汇编而不是 68000 的版本吗?或者有没有对 AMD64 指令集精简版的温和介绍,好让我自己动手?指令集很大,有一组能完成工作的原始命令会不错。
ainar-g查看英文原文
I love this series! Does anybody know, if anyone ever made a version that outputs AMD64 assembly instead of 68000? Or some kind of gentle introduction to a reduced version of the AMD64 instruction set, so that I could do it myself? The instruction set is quite huge, so having a number of primitive commands that get the job done would be nice.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选