CPython使用什么解析器生成器? [英] What parser generator does CPython use?

查看:94
本文介绍了CPython使用什么解析器生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读文档中的此页面,并且注意到它说

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

这是完整的Python语法,由解析器生成器读取 并用来解析Python源文件

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

但是,我很难找出CPython使用的解析器生成器.那么CPython使用什么解析器生成器?是否还有其他解析器生成器可以在不做任何修改的情况下采用该页面上的语法?

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?

推荐答案

Python是开源的,因此您可以检查源代码...

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

在Python源目录中是一个解析器"目录,其中包含带有注释的"Python.asdl"

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

同一目录中还有一个"asdl.py"文件...

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
"""

因此,它似乎是一个自定义解析器生成器. LALR(1)解析器生成器并不难编写.

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

这篇关于CPython使用什么解析器生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆