C parsing fun

Károly Kiripolszky karoly.kiripolszky at gmail.com
Tue Feb 6 07:44:07 EST 2007


Helo again!

When I came up with this idea on how to parse C files with ease, I was
at home and I only have access to the sources in subject in the
office. So I've tried the previously posted algorithm on the actual
source today and I realized my originally example data I've ran the
test with was so simple, that with some header files the algorithm
still failed. I had to make some further changes and by now I was able
to parse 1135 header files in 5 seconds with no errors.

This may be considered as spamming, but this package is so small I
don't wan't to create a page for it on SF or Google Code. Furthermore
I want to provide people who find this topic a working solution, so
here's the latest not-so-elegant-brute-force-but-fast parser:

http://kiri.csing.hu/stack/python/bloppy-0.3.zip

On Feb 5, 1:43 pm, "karoly.kiripolszky" <karoly.kiripols... at gmail.com>
wrote:
> Helo ppl!
>
> At the job I was given the task to make a script to analyze C++ code
> based on concepts my boss had. To do this I needed to represent C++
> code structure in Python somehow. I read the docs for Yapps, pyparsing
> and other stuff like those, then I came up with a very simple idea. I
> realized that bracketed code is almost like a Python list, except I
> have to replace curly brackets with squared ones and surround the
> remaining stuff with quotes. This process invokes no recursion or node
> objects, only pure string manipulations so I believe it's really fast.
> Finally I can get the resulting list by calling eval() with the
> string.
>
> For example when I need to parse a class definition, I only need to
> look for a list item containing the pattern "*class*", and the next
> item will be the contents of the class as another list.
>
> You can grab the code at:
>
> http://kiri.csing.hu/stack/python/bloppy-0.1.zip
>
> (test script [test.py] included)





More information about the Python-list mailing list