dongyan3562 2015-07-08 20:14
浏览 194

在Go中解析s表达式

Here's a link to lis.py if you're unfamiliar: http://norvig.com/lispy.html

I'm trying to implement a tiny lisp interpreter in Go. I've been inspired by Peter Norvig's Lis.py lisp implementation in Python.

My problem is I can't think of a single somewhat efficient way to parse the s-expressions. I had thought of a counter that would increment by 1 when it see's a "(" and that would decrement when it sees a ")". This way when the counter is 0 you know you've got a complete expression.

But the problem with that is that it means you have to loop for every single expression which would make the interpreter incredibly slow for any large program.

Any alternative ideas would be great because I can't think of any better way.

  • 写回答

2条回答 默认 最新

  • douxie7339 2015-07-09 22:33
    关注

    There is an S-expression parser implemented in Go at Rosetta code:

    S-expression parser in Go

    It might give you an idea of how to attack the problem.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料