《crafting interpreters》阅读第 23 天,p45-p45 总结,总计 1 页。
一、内容
章:04.Scanning,节:4.6 Longer Lexemes
内容:词法分析之处理注释。
二、开发总结
1.处理注释逻辑
注释符号://。要和除号 / 放在一起处理。
注释的形式:// xxx。只支持单行注释。
判断注释结束逻辑:遇到换行符 \n。
2.源代码点评
ef peek(self) -> str:
"""
:return:
"""
# todo 源代码中的这部分不知道什么场景会出现,先注释
# if self.is_at_end():
# return "\0"
return self.source[self.current]
3.Java vs Python
1.获取字符串中的字符
Java:charAt(int index)
Python: strindex
4.Python 代码实现
https://github.com/codists/pylox
三、Python 技术总结
1.\0
表示 ASCII 码为 0 的那个字符。
2.字符串操作
获取字符:strindex
四、其它
前面的阅读内容,偏理论,后续有时间再写总结。
还是不喜欢用 scanning 命名章,应该用 lexical analysis 更准确。
虽然有了 AI agent,但是写代码的过程中始终会有一个疑问:这样写好不好,对后续有没有影响?我的处理方式依然是:先不要去想那么多,先把事情干完,干完再去优化。
五、参考资料
1. 编程
(1) 豆瓣,Robert Nystrom,《Crafting Interpreters》:https://book.douban.com/subject/35548379/
(2)Github,craftinginterpreters: https://github.com/munificent/craftinginterpreters
(3)Github,Python 实现:https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations#python
2. 英语
(1) Etymology Dictionary:https://www.etymonline.com
(2) Cambridge Dictionary:https://dictionary.cambridge.org
欢迎搜索及关注:编程人(a_codists)