-->

Is Python 3.5's grammar LL(1)?

2020-07-10 06:47发布

问题:

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:

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.