编程与软件工程ducklang.org
设计一门编程语言
Designing a Programming Language
2015 — 2022,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是一篇系列教程的开篇,作者以循序渐进的方式讲解如何设计并实现一门编程语言,内容涵盖词法分析器、解析器直到抽象语法树(AST)的构建。文章从简单概念入手,逐步深入到语言实现的核心技术环节。
为什么经久不衰:它多次跨越年份登上首页,说明'如何造一门语言'这一主题持续吸引开发者,是了解解释器与语言实现原理的经典入门材料。
HN 评论精选
文章难度曲线陡峭,前易后难,解析器部分对初学者不友好
文章开头采用简单、渐进的方式,直到讨论词法分析器和程序输入处理,概念都很容易理解。但随后材料密度突然大幅上升,关于解析器的讨论对不熟悉这些技术的读者来说非常晦涩。前半部分写得相当入门,毫无防备的初学者很可能读到一半就感到不堪重负而放弃。解析确实是个很难教的主题,但它是读者理解语言构建的核心。或许从解析的目标(AST)出发、倒推讲解解析过程会更有意义。
jrapdx3查看英文原文
The article starts out with a simple, incremental approach, pretty easy to grasp the concepts all the way through the discussion of the lexer and digesting the program input. Then all of a sudden the density of the material accelerates dramatically. The discussion of the parser, and parsing as it applies to the language, becomes very opaque to readers not already familiar with the technologies being described. It's perfectly OK to proceed that way for a sophisticated audience, but the first part of the article is written at a much more introductory level. An unsuspecting beginner may very likely feel overwhelmed about half-way through, and probably give up at that point. When I got to the explanation of the AST, no surprise, it was exactly representable as an sexpr, which anyone with a few hours experience with Lisp or Scheme would recognize. Not sure, maybe it would have made more sense to begin with the parsed goal (the AST) and work backwards to explicate how parsing of the original syntax was done. I guess parsing is a really hard subject to teach, but it's the core idea that the reader needs to grasp to be able to understand PL construction as the author laid it out. A still gentler introduction could be possible, if it doesn't sound so easy to do.
反驳文中'C 高度可移植'的说法,指出编写可移植 C 实际上非常困难
针对'C 程序可以部署到几乎所有操作系统'这一说法,我要打破这个幻觉:虽然理论上可以写出这样的 C 代码,但实际做到非常难。不同操作系统的系统调用不同,即使同属一系(如 Linux 与 Solaris)语义也可能有差异;基本类型的宽度也不一致,'long' 在不同平台上宽度不同,某些特殊系统上 'char' 甚至可以是 16 位。写一个简单的 socket 服务器,尝试在 Windows、Linux 和 Solaris 上运行,再混合 32/64 位,看看你是否还持同样观点。
toolslive查看英文原文
"A program written in C can be deployed on virtually any operating system". Let me kill that illusion: While it is possible to write C that can be deployed on virtually any operating system, doing so is quite hard. Operating systems have different system calls, and even if they are the same family (Linux vs Solaris fe) the semantics can differ. Another thing is that the resolution of the basic primitive types can vary: 'long' is not equally wide on all platforms, heck, even 'char' can be 16 bits on some exotic systems. Anyway, writing portable C is an extra level of complexity. Just write up a little socket server in C and try to get it running on Windows, Linux and Solaris, maybe mix in 32 and 64 bit and see if you still have the same opinion afterwards.
批评标题名不副实,内容是解释器实现而非语言设计
是的。这个页面其实不是关于'设计'一门编程语言,而是关于实现一个解释器——没有任何实际的设计,只有实现。
IncRnd查看英文原文
Yea. This page isn't about Designing a Programming Language. The page is about Implementing an Interpreter of a Programming Language without any actual design, just implementation.
呼吁语言设计成为独立学科,不应总由实现者兼任
我希望有一天语言设计能成为一门独立的学科。这让我想起互联网早期,开发者是唯一的网页设计师。大多数编程语言是由实现它们的人设计的。常见的批评是语言设计者可能创造出与计算机自身限制不兼容的语法,但这和网页设计师要学会在浏览器约束下做出好看的设计是同样的挑战。
awb查看英文原文
I hope that at some point language design will become a self-contained discipline. It reminds me of back in the early days of the Internet when developers were the only web designers. Most programming languages are designed by the same people implementing them. The common critique is that language designers might create a syntax incompatible with the limitations of the computer itself, but that’s the same challenge web designers had to learn in designing something that will look great in the constraints of the browser, and not just look good in Photoshop.
历次讨论
同类还值得读
开源应用架构
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编辑精选