Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy

rocky rocky at gnu.org
Wed Jun 8 06:38:47 EDT 2016

For those who are interested in experimenting with parser systems in Python, there has been one around for a long while. But in my opinion it was a bit lacking in graded example demonstrating how to use it.

So in the recently in spark_parser 1.3.0 [1], I've beefed up the examples a little. In addition to the example programs which give the classic arithmetic expression evaluator, I now include the beginnings of a full Python 2.6 language. The semantic routines just reformat the input which was parsed into a tree and spit that back out formatted according to predefined rules. Included is the grammar file from the 2.6.9 distribution.

For those who want to go further and see a full production-like example, see the uncompyle6 github repository[2] which uses this. It reads bytecode from Python versions 2.3 to 3.5 or so and produces the corresponding Python 2 or Python 3 source code.

Alternatively if you want to understand how uncompyle6 works, such as to improve it or fix bugs, you'll probably need to understand how the parser system it uses works.

[1] https://pypi.python.org/pypi/spark_parser/1.3.0
[2] https://github.com/rocky/python-uncompyle6

More information about the Python-list mailing list