Is there a python library to parse C++ code file?

439 views
Skip to first unread message

Allerdy...@gmail.com

unread,
Mar 16, 2006, 10:27:26 PM3/16/06
to
Is there a python library to parse C++ code file?
If yes, can you please tell me where is it?

Thank you.

Fredrik Lundh

unread,
Mar 17, 2006, 1:57:35 AM3/17/06
to pytho...@python.org
Allerdy...@gmail.com wrote:

> Is there a python library to parse C++ code file?
> If yes, can you please tell me where is it?

depends on how you want to parse the file, and what information you
want to extract. without more details, I'd recommend

http://www.gccxml.org/HTML/Index.html

combined with some python xml library, e.g.

http://www.effbot.org/zone/element-index.htm
http://www.effbot.org/zone/element-iterparse.htm

which gives you something like:

http://www.boost.org/libs/python/pyste/

which might be a good thing to look at before you start ...

or maybe you had something much simpler in mind ?

</F>

Roman Yakovenko

unread,
Mar 17, 2006, 1:19:51 PM3/17/06
to Fredrik Lundh, pytho...@python.org
On 3/17/06, Fredrik Lundh <fre...@pythonware.com> wrote:

> Allerdy...@gmail.com wrote:
>
> > Is there a python library to parse C++ code file?
> > If yes, can you please tell me where is it?

pygccxml.

http://www.language-binding.net/pygccxml/pygccxml.html

Very powerful package :-)! It has built-in support for type analisys,
cache and ....


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/

buddin...@gmail.com

unread,
Apr 27, 2015, 2:34:08 PM4/27/15
to
I want to parse a C++ code to get class names, method names, the blocks inside method, methods inside method, identify recursive call, methods of class(outside the class), and relationships of classes. How to do it in python? Is there any library to do it?

Steven D'Aprano

unread,
Apr 27, 2015, 8:29:23 PM4/27/15
to
Have you googled for "C++ parse python"? What results did you find?

https://duckduckgo.com/?q=parse%20C%2B%2B%20python


C++ is notorious for being so complex that it is very difficult to parse
correctly. I believe that most so-called C++ parsers fail to parse it
correctly (obviously some do, otherwise there would be no working C++
compilers).

Perhaps SWIG may be able to help you? It claims to be able to export the
parse tree of the C++ code as XML, which you could then analyse in Python.

http://www.swig.org/compare.html
http://www.swig.org/article_cpp.html



--
Steven

Reply all
Reply to author
Forward
0 new messages