Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Python spec says Python is PEG, so you should use PEG parser for parsing Python.

Python switched to PEG in IIRC 3.9, the language standard, parser and the grammer were previously CFG, specifically LL(1).

That switch implies that maybe the author is only correct until your language is widely (if not wildly) successful?

https://peps.python.org/pep-0617/



I think the main issue here is that you in general just don't "get a CFG" parser which magically works correct with nice ergonomics and grate performance.

You get a LL(1), LR(1), LALR(1), etc. parser and the more of CFG they can parse the more drawbacks there often are.

And making a programming language fit into more limited parsers like LL(1) is a total pain.

So you need something which is more powerful, but still not to complicated to have a fast efficient implementation for python and python tooling.

At which point it can be simpler to just go with PEG especially if you have the amount of people and brain power to make sure you don't slip up with resolving ambiguity in a arbitrary "accidental" way.


Core.py episode on the transition to the parser mentioned limitations of the LL(1) parser wrt to new syntax.[1][2]

There were some positive side effects to the move and it enabled better exceptions, with more detailed information.

[1] https://podcasts.apple.com/us/podcast/episode-8-the-new-pars...

[2]https://podcasts.apple.com/us/podcast/episode-7-the-old-pars...




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: