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}
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..

E4X, ActionScript 3 new “sublanguage”

Since I’ve heard the voices about the upcoming E4x in actionscript 3 I awaited this moment…
Finally ActionScript supports E4X and we can kick away the old XML object (always supported for backward compatibility)! we can stop using all the various xml2object classes created in these years, we finally have a validating parser, so we will see finally well formatted XML files from flash users 🙂
But finally we have a powerful “language” with a very strong syntax.

I’ve written a small tutorial with a quick guide  about actionscript3 and e4x basic syntax (without including Namespaces and QNames for the moment)

http://www.sephiroth.it/tutorials/flashPHP/E4X/index.php

P.s. I forgot to say that E4X is also available in the Geko1.8 browser (such as Firefox 1.5). For more info see this article: http://developer.mozilla.org/en/docs/E4X. Unfortunately E4X ins’t supported by python, neither there’s a module for it 🙁

Will Flash 8 support E4X?

An unintentionally mail posted in the Flex mailing list talks about one of the new Flex 2.0 features, the support of E4X.
This means that probably the new flash player will support it also… This should be a great step over the old “DOM” flash support.. in this case XML entities will be threated as builtins objects Read more about ECMAScript for XML (E4X) Specification: http://www.ecma-international.org/publications/standards/Ecma-357.htm

see the original post