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

Discussion in 'C++' started by kuangye, Mar 13, 2011.

  1. kuangye

    kuangye Guest

    Hi, all. I need to generate other programming languages 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
    develop on this library.

    It would be better that the library is implemented by dynamical
    language (such as python,...)

    Since the project's 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. kuangye

    Öö Tiib Guest

    On Mar 13, 11:23 am, kuangye <> wrote:
    > Hi, all. I need to generate other programming languages 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
    > develop on this library.


    There are several open source C++ compilers. Two of these (g++ and
    CLang) are quite modern. Several C++ compilers (both commercial and
    modern) have options to process C++ code into parsed syntax tree.

    > It would be better that the library is implemented by dynamical
    > language (such as python,...)


    All the C++ compilers i know of are implemented in C or in C++.

    > Since the project's C++ source code is rather simple and regular. I
    > think i can generate other language representation from C++ source
    > code.


    I think that you have decided to solve complex task by solving even
    way more complex task. Translating a code base from C++ to something
    else is lot simpler task than writing a translator that does it. Good
    luck.
     
    Öö Tiib, Mar 13, 2011
    #2
    1. Advertising

  3. kuangye

    kuangye Guest

    On Mar 13, 9:19 pm, Öö Tiib <> wrote:
    > On Mar 13, 11:23 am, kuangye <> wrote:
    >
    >
    > I think that you have decided to solve complex task by solving even
    > way more complex task. Translating a code base from C++ to something
    > else is lot simpler task than writing a translator that does it. Good
    > luck.


    Thank you Tiib.

    Since I may have to support other languages(such as: C#, Java, Python,
    Action script, ...).
    (In fact, this is a long term target. Now I'm just thinking how to do
    it easily and maintainably)
    It would be a big burden without a automation tool. especially when we
    upgrade our library.
    That's why i expect to generate other language's code automatically
    (or semi-automatically) from C++ source code.

    And seems that the tool may be a new big burden.
     
    kuangye, Mar 16, 2011
    #3
  4. On Mar 16, 4:43 am, kuangye <> wrote:
    > On Mar 13, 9:19 pm, Öö Tiib <> wrote:
    >
    > > On Mar 13, 11:23 am, kuangye <> wrote:

    >
    > > I think that you have decided to solve complex task by solving even
    > > way more complex task. Translating a code base from C++ to something
    > > else is lot simpler task than writing a translator that does it. Good
    > > luck.

    >
    > Thank you Tiib.
    >
    > Since I may have to support other languages(such as: C#, Java, Python,
    > Action script, ...).
    > (In fact, this is a long term target. Now I'm just thinking how to do
    > it easily and maintainably)
    > It would be a big burden without a automation tool. especially when we
    > upgrade our library.
    > That's why i expect to generate other language's code automatically
    > (or semi-automatically) from C++ source code.
    >
    > And seems that the tool may be a new big burden.


    In that case I suggest you first translate your code to a language
    independent representation or a clean language like Lisp. Then write
    a code generator for each target language that takes your base
    representation as input. This is still a huge task but saves you
    from addressing the full details of C++ in particular.
     
    Gert-Jan de Vos, Mar 16, 2011
    #4
  5. kuangye

    Puppet_Sock Guest

    On Mar 13, 5:23 am, kuangye <> wrote:
    [snip]
    > I need to generate other programming languages source code
    > from C++ source code for a project.


    Whatever for? Moving to another language using
    automated tools is a lot like a dancing bear.
    The wonder isn't how good the bear is at dancing,
    but that it dances at all.
    Socks
     
    Puppet_Sock, Mar 16, 2011
    #5
  6. kuangye

    tm Guest

    On 16 Mrz., 05:43, kuangye <> wrote:
    > On Mar 13, 9:19 pm, Öö Tiib <> wrote:
    >
    > > On Mar 13, 11:23 am, kuangye <> wrote:

    >
    > > I think that you have decided to solve complex task by solving even
    > > way more complex task. Translating a code base from C++ to something
    > > else is lot simpler task than writing a translator that does it. Good
    > > luck.

    >
    > Thank you Tiib.
    >
    > Since I may have to support other languages(such as: C#, Java, Python,
    > Action script, ...).


    A huge task...
    Is it necessary that your target program is readable or is it
    sufficient when the corresponding compiler / interpreter accepts it?

    BTW.: Choosing a less feature rich programming language as source
    would make the task easier. Keep in mind that features not present
    in the target language must be emulated (e.g.: When your target
    language has no templates you must do them).

    My Seed7 to C compiler does not try to generate good looking C
    programs. Still it has a size of more than 20000 lines (not counting
    the lines in the libraries / include files used).

    The problems writing the Seed7 to C compiler came from features not
    present in C (overloading, OO with multiple dispatch, closures,
    local functions, exceptions, automatic memory management,
    big integer support, portable access to files and directories,
    unicode support, portable graphics library, portable
    console / terminal window support ... ).

    For me it turned out that targeting a language is not sufficient.
    There are several hardware / operating system / C compiler details
    that must be taken into account. The Seed7 to C compiler and
    the Seed7 runtime library together support several C compiler /
    operating system / hardware combinations, but they must be
    configured to use them.


    Greetings Thomas Mertes

    --
    Seed7 Homepage: http://seed7.sourceforge.net
    Seed7 - The extensible programming language: User defined statements
    and operators, abstract data types, templates without special
    syntax, OO with interfaces and multiple dispatch, statically typed,
    interpreted or compiled, portable, runs under linux/unix/windows.
     
    tm, Mar 29, 2011
    #6
    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:
    386
    Roman Yakovenko
    Mar 17, 2006
  4. kuangye
    Replies:
    3
    Views:
    574
    Philip Semanchuk
    Mar 13, 2011
  5. kuangye
    Replies:
    0
    Views:
    242
    kuangye
    Mar 13, 2011
Loading...

Share This Page