../mal-step1-read-print
Make A Lisp[1]-读取&输出
Published:
pl
lisp
瞎折腾
这一步应该是所有后续步骤的根基了, 文本流-> token -> 内部数据类型 -> 可读的输出. REPL 的 R(read) , P(print) 基本就实现了. 后续大部分是完善 EVAL 的过程了.
解决方案
REF: step-1-read-and-print 理论什么的,没什么高深支出, 相对于 编译原理 这种难啃的骨头, 这篇 guide 可谓简洁. 毕竟 lisp 的代码就是 ast... , 相对来讲解析会简单很多.
TIPS
采用 interface 作为 mal 语言的根类型. 所有的类型均不可变.
USE
make test^java2^step1
稍显繁琐, 于是在 shell 里加了方法
function tm() {
make test^java2^step$1
}
tm 1 # like this.
结
read_form, read_list 的递归解析实现了 mal 的语法分析. PR: https://github.com/guxingke/mal/pull/12