Menu:

Sponsor

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

Follow Me

 

Forum's topics

Latest Files

Archives

Top Rated

Categories

Photo Gallery


Alessandro Crugnola on January 16, 2007 in actionscript , python

Actionscript parsing experiences: PyBison & PLY

My experiments with text-parsing continue..

PyBison
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 run.py file accept these parameters:

usage: run.py [options]

options:
  -h, --help            show this help message and exit
  -v, --verbose         Turn on verbose mode
  -o OUTPUT_FILE, --output=OUTPUT_FILE
                        Don't print to stdout but to the output file
  -i INPUT_FILE, --input=INPUT_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

 

PLY
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 run.py {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 

 

2 comments
the ply source code tar is empty http://www.sephiroth.it/_temp/ply.tar.gz
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.





 

TrackBacks

TrackBack URL for this entry: http://www.sephiroth.it/cgi-bin/mt/mt-tb.cgi/184