Is there any python library that parse c++ source code statically

Discussion in 'Python' started by kuangye, Mar 13, 2011.

  1. kuangye

    kuangye Guest

    Hi, all. I need to generate other programming language source code
    from C++ source code for a project. To achieve this, the first step is
    to "understand" the c++ source code at least in formally. Thus is
    there any library to parse the C++ source code statically. So I can
    developer on this library.

    Since the C++ source code is rather simple and regular. I think i can
    generate other language representation from C++ source code.
     
    kuangye, Mar 13, 2011
    #1
    1. Advertising

  2. On 13 Mar, 10:14, kuangye <> wrote:
    > Hi, all. I need to generate other programming language source code
    > from C++ source code for a project. To achieve this, the first step is
    > to "understand" the c++ source code at least in formally. Thus is
    > there any library to parse the C++ source code statically. So I can
    > developer on this library.
    >
    > Since the C++ source code is rather simple and regular. I think i can
    > generate other language representation from C++ source code.



    The problem is that C++ is a beast of a language and is not easy to
    find full parsers for it.
    I've never done it, but sometime I researched possible ways to do it.
    The best idea I could come with
    is doing it in 2 steps:

    - using gcc-xml ( http://www.gccxml.org/HTML/Index.html ) to generate
    an xml representation of the code
    - using one of the many xml library for python to read the xml
    equivalent of the code and then generate the equivalent
    code in other languages ( where you could use a template engine,
    but I found that the python built-in string
    formatting libraries are quite up to the task ).

    HTH

    Ciao
    ---
    FB
     
    Francesco Bochicchio, Mar 13, 2011
    #2
    1. Advertising

  3. Francesco Bochicchio, 13.03.2011 10:37:
    > On 13 Mar, 10:14, kuangye<> wrote:
    >> Hi, all. I need to generate other programming language source code
    >> from C++ source code for a project. To achieve this, the first step is
    >> to "understand" the c++ source code at least in formally. Thus is
    >> there any library to parse the C++ source code statically. So I can
    >> developer on this library.
    >>
    >> Since the C++ source code is rather simple and regular. I think i can
    >> generate other language representation from C++ source code.

    >
    >
    > The problem is that C++ is a beast of a language and is not easy to
    > find full parsers for it.
    > I've never done it, but sometime I researched possible ways to do it.
    > The best idea I could come with
    > is doing it in 2 steps:
    >
    > - using gcc-xml ( http://www.gccxml.org/HTML/Index.html ) to generate
    > an xml representation of the code
    > - using one of the many xml library for python to read the xml
    > equivalent of the code and then generate the equivalent
    > code in other languages ( where you could use a template engine,
    > but I found that the python built-in string
    > formatting libraries are quite up to the task ).


    I also heard that clang is supposed to the quite useful for this kind of
    undertaking.

    Stefan
     
    Stefan Behnel, Mar 13, 2011
    #3
  4. On Mar 13, 2011, at 11:46 AM, Stefan Behnel wrote:

    > Francesco Bochicchio, 13.03.2011 10:37:
    >> On 13 Mar, 10:14, kuangye<> wrote:
    >>> Hi, all. I need to generate other programming language source code
    >>> from C++ source code for a project. To achieve this, the first step is
    >>> to "understand" the c++ source code at least in formally. Thus is
    >>> there any library to parse the C++ source code statically. So I can
    >>> developer on this library.
    >>>
    >>> Since the C++ source code is rather simple and regular. I think i can
    >>> generate other language representation from C++ source code.

    >>
    >>
    >> The problem is that C++ is a beast of a language and is not easy to
    >> find full parsers for it.
    >> I've never done it, but sometime I researched possible ways to do it.
    >> The best idea I could come with
    >> is doing it in 2 steps:
    >>
    >> - using gcc-xml ( http://www.gccxml.org/HTML/Index.html ) to generate
    >> an xml representation of the code
    >> - using one of the many xml library for python to read the xml
    >> equivalent of the code and then generate the equivalent
    >> code in other languages ( where you could use a template engine,
    >> but I found that the python built-in string
    >> formatting libraries are quite up to the task ).

    >
    > I also heard that clang is supposed to the quite useful for this kind of undertaking.


    I was just discussing this with some folks here at PyCon. Clang has a library interface (libclang):
    http://clang.llvm.org/doxygen/group__CINDEX.html

    There's Python bindings for it; I'm sure the author would like some company =)

    https://bitbucket.org/binet/py-clang/


    Cheers
    P
     
    Philip Semanchuk, Mar 13, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Paul Diffenbach

    statically allocated data structures source?

    Thomas Paul Diffenbach, Jul 11, 2003, in forum: C Programming
    Replies:
    4
    Views:
    457
    David Rubin
    Jul 12, 2003
  2. Replies:
    2
    Views:
    431
    Tom St Denis
    May 30, 2004
  3. Replies:
    2
    Views:
    385
    Roman Yakovenko
    Mar 17, 2006
  4. kuangye
    Replies:
    0
    Views:
    242
    kuangye
    Mar 13, 2011
  5. kuangye
    Replies:
    5
    Views:
    846
Loading...

Share This Page