用 PHP 写一个"编程语言"
php-lisp
php-lisp 是一个用PHP写的lisp解释器 (Just for fun)
简介
- 单元测试覆盖率 93%
- 全部使用
php declare(strict_types=1);
严格模式 - 核心解释器0依赖 打包好的 phar 文件只有 57K
安装
-
使用 composer 安装
composer require php-lisp/php-lisp
-
下载 Phar 文件
wget https://github.com/php-lisp/php-lisp/releases/download/v1.0.1/psp
-
clone 代码
git clone git@github.com:php-lisp/php-lisp.git
cd php-lisp && composer install && ./bin/psp -h
使用
-
使用 REPL
./psp
-
查看帮助
./bin/psp -h
-
执行 psp 代码
echo '(define zero (lambda (f) (lambda (x) x))) (define one (lambda (f) (lambda (x) (f x)))) (define plus (lambda (m n) (lambda (f) (lambda (x) ((n f) ((m f) x)))))) (define mult (lambda (m n) (lambda (f) (lambda (x) ((n (m f)) x))))) (define xp (lambda (m n) (lambda (f) (lambda (x) (((n m) f) x))))) (define pr (lambda (x) (do (echo x) x))) (define prn (lambda (n) (do ((n pr) ".") (echo "\n")))) (define two (plus one one)) (define three (plus two one)) (define six (mult two three)) (define sixty-four (xp two six)) (prn sixty-four)' >> church-encoding.psp && ./bin/psp church-encoding.psp
更多 Demo 查看 https://github.com/php-lisp/php-lisp/tree/...
参考
REPL
LISP
pharen
lispphp
mal
pEigthP
交流与反馈
Email: itwujunze#gamil.com
本作品采用《CC 协议》,转载必须注明作者和本文链接
:speak_no_evil: