[实作] J002:minimal LISP with FORTH core

楼主: jans0204 (jans0204)   2022-08-20 09:53:47
J002:minimal LISP with FORTH core
1. 下载原始码:
#
# Interpreter for a minimal LISP-like language (in 1k lines of C)
#
https://github.com/robertostling/lisp1k # lisp1k-master.zip
2. 下载标头档:
#
# stdarg.h
#
https://sites.uclouvain.be/SystInfo/usr/include/stdarg.h
3. 制作空标头档:
打开 notepad (记事本),不用输入内容,就另存新档:alloca.h, error.h
4. 编写补钉码:
//
// error.c
//
#include <error.h>
#include <stdarg.h>
#include <stdio.h>
void error (int status, int errnum, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, fmt, ap);
fputc('\n', stderr);
va_end(ap);
exit(status);
}
5. 编写编译码:
::
:: mk-exe.bat
::
if exist lisp1k.log del lisp1k.log
if exist lisp1k.exe del lisp1k.exe
gcc -I. -o lisp1k.exe lisp.c error.c > lisp1k.log 2>&1
6. 抽取 lisp1k-master.zip\lisp1k-master\*.* 至工作目录,例如:R:\src\
(RAMDRIVE)
7. 将 stdarg.h, alloca.h, error.h, error.c, mk-exe.bat 五档案加入 R:\src\
8. 在 R:\src\ 开启 Console Cmd (命令提示字符),执行 mk-exe.bat 开始编译,产生
lisp1k.exe
9. 测试:
R:\src>lisp1k.exe < test.lsp
"Please have some factorials."
(1 2 6 24 120 720 5040 40320 362880 3628800 39916800 479001600 6227020800)
R:\src>
10. 编译环境:gcc 3.4.5 (2004) (mingw-vista special r3)
用 postfix 的 FORTH core 来制作 prefix 的 LISP interpreter,两者的同质性,
更显现制作的简洁。
(END)
https://github.com/jans0204/J002-minimal-LISP-with-FORTH-core

Links booklink

Contact Us: admin [ a t ] ucptt.com