60行R++代码实现Lisp解释器
来源:互联网 发布:新网中文域名 编辑:程序博客网 时间:2024/06/01 08:56
还没有处理lambda、上下文等,有待完善。
main{forputsl(eval(getsl))}rstr eval(rstr s){return eval(tokenize(s).split(' '))}rstr eval(rbuf<rstr>& v){if v.get(0)!='('return v.get(0)next=find(v.sub(2))+2switch v.get(1)case '+'return eval(v.sub(2,next)).toint+eval(v.sub(next,v.count-1)).tointcase '-'return eval(v.sub(2,next)).toint-eval(v.sub(next,v.count-1)).tointcase '*'return eval(v.sub(2,next)).toint*eval(v.sub(next,v.count-1)).tointcase '/'return eval(v.sub(2,next)).toint/eval(v.sub(next,v.count-1)).tointreturn ''}int find(rbuf<rstr>& v){return r_cond(v.get(0)=='(',find_sbk(v)+1,1)}int find_sbk(rbuf<rstr>& v){count=0for i in vif '('==v[i]++countif ')'==v[i]--countif 0==countreturn ireturn v.count}rstr tokenize(rstr s){rstr retfor i in sif s[i]==`(ret+=' ( 'elif s[i]==`)ret+=' ) 'elif s[i]==0xa||s[i]==0xd||s[i]==9ret+=' 'elseret+=s[i]return ret}
0 0
- 60行R++代码实现Lisp解释器
- Lisp解释器
- 用Lisp解释Lisp
- JavaScript 编写的迷你 Lisp 解释器
- JavaScript 编写的迷你 Lisp 解释器
- Ubuntu下安装Scheme/Lisp解释器
- BJTU 1687 lisp的解释器
- R语言13行代码实现神经网络
- 几个免费的Scheme(Lisp)解释器
- (如何写 (Lisp) 解释器 (用Ruby哦))
- 如何使用Python编写一个Lisp解释器
- 几个免费的Scheme(Lisp)解释器
- 56种语言编写一个Lisp解释器
- lisp实现的专家系统
- Lisp实现快速排序
- Lisp---实现阶乘
- map的lisp实现
- Apache Zeppelin 中 R 解释器
- VisualSVN在客户端使用ApacehPasswd修改密码
- 使用 Python 进行稳定可靠的文件操作
- 如何让php执行shell
- 初识缓存以及ehcache初体验
- Using NTFSClone to clone NTFS volumes super fast
- 60行R++代码实现Lisp解释器
- 菜鸟也能学cocos2dx 3.0 伊始(一)
- oracle 数据库全库备份[转]
- error"Cannot declare member function ...to have static linkage"
- MPI 实现梯形积分法
- 博客新开,欢迎来访
- 浅析MySQL中exists与in的使用
- __bridge,__bridge_transfer和__bridge_retained详解
- redmine与svn完美集成方案