我正在读书这一页 http://docs.python.org/py3k/reference/grammar.html在文档中,并注意到它说
这是完整的 Python 语法,由解析器生成器读取
并用于解析Python源文件
但是,我很难找出 CPython 使用的解析器生成器。那么 CPython 使用什么解析器生成器呢?是否有其他解析器生成器可以在不进行任何修改的情况下获取该页面上的语法?
Python 是开源的,因此您可以检查源代码...
在Python源目录中有一个“Parser”目录,其中包含“Python.asdl”和注释
-- ASDL's four builtin types are identifier, int, string, object
同一目录中还有一个“asdl.py”文件......
"""An implementation of the Zephyr Abstract Syntax Definition Language.
See http://asdl.sourceforge.net/ http://asdl.sourceforge.net/ and
http://www.cs.princeton.edu/research/techreps/TR-554-97 http://www.cs.princeton.edu/research/techreps/TR-554-97
Only supports top level module decl, not view. I'm guessing that view
is intended to support the browser and I'm not interested in the
browser.
Changes for Python: Add support for module versions
"""
所以看起来它是一个自定义解析器生成器。 LALR(1) 解析器生成器并不难编写。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)