续前文,集成了四则运算语法分析器。运行效果如下:
$ python3 交互环境.py
Welcome to ulang's REPL..
Type 'help' for more informations.
> 2*5/3
3.3333333333333335
> 1-4
-3
> (1+2)*3-4
5
> quit
除了之前的语法分析器,只加了此方法:
class 木兰(cmd.Cmd):
...
def default(self, line):
print(分析器.parse(分词器.lex(line)).求值())
接下去还需验证将代码转换为 Python 语法树后再执行的关键技术。
页面更新:2024-02-28
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号