Welcome to PyBison!
Bringing GNU Bison/Flex's raw speed and power to Python
What is PyBison?
PyBison is a framework which effectively 'wraps' Bison and Flex into a Python class structure.
You define a parser class, define tokens and precedences as attributes, and parse targets as methods with rules in the docstrings, then instantiate and run.
Black Magick happens in the background, whereupon you get callbacks each time
yyparse() resolves a parse target.
Now, install pybison with:
pip install pybison
The following command will verify if the installation succeeded:
python -c "import bison"
There are already parsers for Python. Why re-invent the wheel?
I looked at all the Python-based parsing frameworks.
IMO, the best one was PLY - a pure-python lexx/yacc implementation (which I have borrowed from heavily in designing PyBison's OO model).
But PLY suffers some major limitations:
- usage of 'named groups' regular expressions in the lexer creates a hard limit of 100 tokens - not enough to comfortably handle major languages
- pure-python implementation is a convenience, but incurs a cruel performance penalty
- the parser engine is SLR, not full LALR(1)
The other frameworks utilise a fiddly script syntax -
How do I use this?
You will need:
We assume that Python, pip and a C compiler is already installed.
First, install the dependencies
sudo pacman -S bison flex
sudo apt-get install bison flex
With Chocolatey, you can install the packages as follows:
choco install winflexbison3
Additionally, if a C compiler is needed, mingw can be installed with Chocolatey as well.
choco install mingw
See the short introduction into debugging.