What parser generator does CPython use?

旧巷老猫 提交于 2020-01-24 03:24:25

问题


I was reading this page in the documentation, and noticed that it says

This is the full Python grammar, as it is read by the parser generator and used to parse Python source files

However, I'm having difficulty finding out what parser generator CPython uses. So what parser generator does CPython use? Are there other parser generators that would take the grammar on that page without any modifications?


回答1:


Python is open-source, so you can inspect the source code...

In the Python source directory is a "Parser" directory containing "Python.asdl" with the note

-- ASDL's four builtin types are identifier, int, string, object

There's also an "asdl.py" file in the same directory...

"""An implementation of the Zephyr Abstract Syntax Definition Language.

See http://asdl.sourceforge.net/ and
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
"""

So it appears that it is a custom parser generator. LALR(1) parser generators are not so hard to write.



来源:https://stackoverflow.com/questions/10748648/what-parser-generator-does-cpython-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!