这个问题可能有重复,但对我来说还不够具体。
python 语法声称是 LL(1),但我注意到Python 语法中的一些表达式确实让我感到困惑,例如,以下函数调用中的参数:
foo(a)
foo(a=a)
Run Code Online (Sandbox Code Playgroud)
对应于以下语法:
argument: ( test [comp_for] |
test '=' test |
'**' test |
'*' test )
Run Code Online (Sandbox Code Playgroud)
test在语法的第一个位置出现两次。这意味着仅通过查看testPython 无法确定它是test [comp_for]或test '=' test.
更多例子:
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
Run Code Online (Sandbox Code Playgroud)
注意'is'和'is' 'not'
subscript: test | [test] ':' [test] [sliceop]
Run Code Online (Sandbox Code Playgroud)
test 也出现了两次。
我对 LL(1) 的理解是错误的吗?Python 是否在词法分析或解析期间对语法进行了一些变通,以使其 LL(1) 可处理?谢谢大家。