Return to David's Python Resources
PyBison - Python-based Parsing at the Speed of C

Getting PyBison

License: GPL (but we will consider applications for licenses for commercial non-open-source deployment)

Introduction

PyBison is a Python binding to the Bison (yacc) and Flex (lex) parser-generator utilities.

It allows parsers to be quickly and easily developed as Python class declarations, and for these parsers to take advantage of the fast and powerful C-based Bison/Flex.

Users write a subclass of a basic Parser object, containing a set of methods and attributes specifying the grammar and lexical analysis rules, and taking callbacks for providing parser input, and receiving parser target events.

Presently, PyBison is only working on Linux (and possibly *BSD-based) systems. However, in time, (or if someone volunteers to help out with probably 2 hours' coding for a small shim layer) it's very possible PyBison will work on Windows as well.


Features

Comparison to Other Python Parsers

This comparison is probably very biased, since it's written by the author of PyBison. However, it should help you to decide whether PyBison is for you.

All the other Python-based parser-construction toolkits I've seen work in pure Python. While this offers conveniences such as not requiring binary compilation, and eliminating dependencies on third-party libraries and other software, it can incur a savage performance penalty.

I've seen some Python parser frameworks which use an idiosyncratic syntax, which I couldn't (or wouldn't) comfortably relate to, especially since I have a background of developing large yacc-based packages. In particular, I wanted to build my parser in genuine Python source files, rather than embedding Python code into a different script language.

On the other hand, I found the PLY parser framework to be much more comfortably Pythonic, in that targets are mapped to class methods. However, I ran into a couple of problems with PLY, namely: With PyBison, I've opted for a system which: The result is a parser toolkit with a Python front end and Python's luxurious comfort, ease of use, but with (most of) the speed and power of traditional bison/yacc-based parsers.