Is Python 3.5's grammar LL(1)?

2020-07-10 06:32发布

I saw http://matt.might.net/teaching/compilers/spring-2015/ saying Python 3.4 is LL(1)

Is Python 3.5's grammar still LL(1) so one can write a recursive descent parser?

1条回答
别忘想泡老子
2楼-- · 2020-07-10 06:41

Yes. This is a deliberate language feature, and not just something that happened to be the case. PEP 3099 explicitly rejected any changes to this for the Python 2 -> 3 transition (a notably bigger transition than any 3.x -> 3.y will be):

  • The parser won't be more complex than LL(1).

    Simple is better than complex. This idea extends to the parser. Restricting Python's grammar to an LL(1) parser is a blessing, not a curse. It puts us in handcuffs that prevent us from going overboard and ending up with funky grammar rules like some other dynamic languages that will go unnamed, such as Perl.

查看更多
登录 后发表回答