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

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Apr 28 02:29:07 CEST 2015


On Tue, 28 Apr 2015 04:33 am, buddingrose11 at gmail.com wrote:

> 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?

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




More information about the Python-list mailing list