Interpreter · course project 解释器 · 课程项目
Mini-Lisp Mini-Lisp 解释器
A small Lisp interpreter in C++ with a parser, lexical scope, closures, macros, a REPL, and script execution.
一个用 C++ 写的小型 Lisp 解释器,包含 parser、词法作用域、闭包、宏、REPL 和脚本执行。

范围
语言很小,但该有的运行时骨架都在
这是北大《软件设计实践》的课程项目。解释器支持 REPL 和脚本执行,值类型包括数字、布尔、字符串、符号、pair / list、空表、过程和宏。
我实现了 tokenizer、parser、带父环境的链式作用域、闭包和特殊形式分派。列表直接由 PairValue 组成,没有借宿主语言的现成 list 偷懒。
语言
从 define 到 quasiquote
特殊形式包括 define、lambda、if、begin、let、cond、短路 and/or、引用和简单宏。内建过程覆盖算术、比较、字符串、I/O 和 map/filter/reduce。
边界
它仍然只是一个教学用解释器
数字统一用 double,没有尾递归优化,错误处理和标准库也很小。把这些边界明确写出来,比假装它接近完整 Scheme 更诚实。
这个项目最有意思的地方,是把“求值”从一个课堂概念变成了一套自己能逐步跟进去的运行规则。
SCOPE
A small language with a real runtime skeleton
This was built for PKU's Software Design Practice course. The interpreter supports a REPL and scripts, with numbers, booleans, strings, symbols, pairs and lists, the empty list, procedures, and macros.
I implemented the tokenizer, parser, parent-linked lexical environments, closures, and special-form dispatch. Lists are built from PairValue rather than borrowed from a host-language list type.
THE LANGUAGE
From define to quasiquote
Special forms include define, lambda, if, begin, let, cond, short-circuiting and/or, quoting, and simple macros. Built-ins cover arithmetic, comparison, strings, I/O, and map/filter/reduce.
LIMITS
It is still a teaching interpreter
Numbers are all double, there is no tail-call optimization, and error handling and the standard library are deliberately small. Stating those limits is more honest than pretending this is a complete Scheme.
The satisfying part was turning “evaluation” from a lecture concept into a set of runtime rules I could step through myself.