我使用keyword内置模块获取当前Python版本所有关键字的列表。我就是这样做的:
>>> import keyword
>>> print(keyword.kwlist)
['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']在keyword.kwlist列表中有__peg_parser__。因此,为了了解它的作用,我在WindowsPython3.9解释器中输入了__peg_parser__ (在Mac和Linux上也可以得到相同的输出),下面是get:
>>> __peg_parser__
File "<stdin>", line 1
__peg_parser__
^
SyntaxError: You found it!所以我的问题是,什么是__peg_parser__,为什么我要得到SyntaxError: You found it!
发布于 2020-12-29 03:46:06
Guido在github 这里上发布了新的聚乙二醇解析器。
它也在Python上。
正如它所提到的:
本文提出用一种新的基于聚乙二醇的解析器取代现有的LL(1)-based解析器。这个新的解析器将允许消除当前语法中存在的多个"hacks“,以绕过LL(1)-limitation。它将大大降低与编译管道相关的一些领域的维护成本,如语法、解析器和AST生成。新的PEG解析器还将取消对当前Python语法的LL(1)限制。
在Python 3.9什么是新的页面中也提到了。
在Python3.10中,LL(1)解析器将被删除。Python3.9使用一个基于PEG的新解析器,而不是LL(1)。
在Python3.6中,没有定义它:
>>> __peg_parser__
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
__peg_parser__
NameError: name '__peg_parser__' is not defined
>>> 发布于 2020-12-29 03:43:41
什么是__peg_parser__?
它是Python (木桩分析器的)中的复活节彩蛋,用于发布新的木桩分析器。正如在这个讨论中提到的,它将在Python3.10中被删除。
在复活节彩蛋被命名为__new_parser__之前,它被改为__peg_parser__,作为未来的证据,就像消息中提到的
new、ex或ng并不是未来的证明名称。我们能把关键字重命名为__peg_parser__吗?
你为什么得到SyntaxError: You found it!
你得到SyntaxError: You found it!是因为它是复活节彩蛋的一部分。
将来会被移除吗?
由于LL(1)解析器将被替换为新的木桩分析器,因此将在Python3.10中删除它。
早期版本和后期版本中的__peg_parser__
它在早期的Python版本中并不存在。
Python3.8及更早版本:
>>> __peg_parser__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not definedPython 3.9:
>>> __peg_parser__
File "<stdin>", line 1
__peg_parser__
^
SyntaxError: You found it!Python 3.10:
>>> __peg_parser__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not definedhttps://stackoverflow.com/questions/65486981
复制相似问题