Skip to content

Commit

Permalink
Published with https://stackedit.io/
Browse files Browse the repository at this point in the history
  • Loading branch information
achun committed Jul 20, 2014
1 parent 48ca812 commit e5b93c8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Chapter07.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ g.Process(script, rec)

Term 的出现, 虽然逻辑上完整了, 代码写出来看上去很丑陋. 看来只有通过辅助函数简化代码了.

# 手工至上

连续两章学习解析器, 事实上笔者自己尝试实现了一个基于 ABNF 的解析器雏形. 然而由于采用了递归的匹配方式, 最终的测试结果让人非常沮丧, 和 go 官方提供的 json 包对比解析速度慢几十倍. go 官方的 json 包是纯手工代码实现的. 采用大家常常听到的先词法分析后语法分析的方法, 事实摆在眼前, 这种手工的方法真的是最快的. 同样的方法我们在 go 的标准库中可以找到多处, 各种教课书中讲的解析相关知识根本就没用上, 效率有目共睹. 直接看相关源代码就能了解细节.

**手工代码构造的先词法分析后语法分析的解析器是最快的**


[1]: http://zh.wikipedia.org/wiki/%E6%89%A9%E5%B1%95%E5%B7%B4%E7%A7%91%E6%96%AF%E8%8C%83%E5%BC%8F
[2]: https://www.google.com.hk/search?q=BNF%20EBNF
Expand Down

0 comments on commit e5b93c8

Please sign in to comment.