Discover Master of Alchemy, our first iPad/iPhone and iPod touch game!

Follow Me


Forum's topics

Latest Files


Top Rated


Photo Gallery

Alessandro Crugnola on January 16, 2007 in actionscript , python

Actionscript parsing experiences: PyBison & PLY

My experiments with text-parsing continue..

Last day I founded a python library (pybison) which runs the generated python parser at near the speed of C-based parsers, due to direct hooks into bison-generated C code.
Cool, unfortunately I couldn't compiled it for Windows and so I made my test on Ubuntu only. What I did was just to export the already written lexer/grammar using bison2py (boundled with pybison) and run it.

If you want to take a look at the python parser try it by downloading the source code here.
The file accept these parameters:

usage: [options]

  -h, --help            show this help message and exit
  -v, --verbose         Turn on verbose mode
                        Don't print to stdout but to the output file
                        Input file to be parsed
  -x, --to-xml          Returns a human-readable xml representation of the
                        parse tree
  -b, --bison-debug     Print the Bison/Flex debug

You can download the source code here


The second test I did was using PLY, an implementation of lex and yacc parsing tools for Python. Being implemented entirely in python it should be much more slower that pybison, but I didn't find any difference with the pybison parser version. In fact PLY , like the traditional bison, creates tables starting from the grammar syntax.
Ok, Both of the implementations are slower that the pure C parser, but extremely faster that antlr!
(They took more or less 0.02 to 0.5 secs for parsing and generating the AST.)
Unlike pybison PLY is still mantained and offers more features and a better error handling.. even if the whole grammar has to be rewritten in python, and it can be compiled in Windows too.

To run the test just write:

python {filename}

I put the source code of the ply implementation here 


P.S. Unfortunately the yacc parser isn't yet complete because I still need to find a way for parsing correctly E4X and XML syntax..



Bookmark and Share


Tags: antlr , bison , parsing , ply , pybison , python , ubuntu , yacc 


the ply source code tar is empty
To make this comparison meaningful, it would have helped if you had mentioned the size of the input files and cpu. 10Kb source file? 10GB log file? 0.5 seconds on what? A 1ghz cpu? A compute cluster?

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Type the characters you see in the picture above.



TrackBack URL for this entry: