Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is there any library that parse c++ source code statically

Reply
Thread Tools

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

 
 
kuangye
Guest
Posts: n/a
 
      03-13-2011

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.

 
Reply With Quote
 
 
 
 
Öö Tiib
Guest
Posts: n/a
 
      03-13-2011
On Mar 13, 11:23*am, kuangye <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
kuangye
Guest
Posts: n/a
 
      03-16-2011
On Mar 13, 9:19*pm, Öö Tiib <(E-Mail Removed)> wrote:
> On Mar 13, 11:23*am, kuangye <(E-Mail Removed)> 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.


 
Reply With Quote
 
Gert-Jan de Vos
Guest
Posts: n/a
 
      03-16-2011
On Mar 16, 4:43*am, kuangye <(E-Mail Removed)> wrote:
> On Mar 13, 9:19*pm, Öö Tiib <(E-Mail Removed)> wrote:
>
> > On Mar 13, 11:23*am, kuangye <(E-Mail Removed)> 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.
 
Reply With Quote
 
Puppet_Sock
Guest
Posts: n/a
 
      03-16-2011
On Mar 13, 5:23*am, kuangye <(E-Mail Removed)> 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
 
Reply With Quote
 
tm
Guest
Posts: n/a
 
      03-29-2011
On 16 Mrz., 05:43, kuangye <(E-Mail Removed)> wrote:
> On Mar 13, 9:19 pm, Öö Tiib <(E-Mail Removed)> wrote:
>
> > On Mar 13, 11:23 am, kuangye <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Is there any python library that parse c++ source code statically kuangye Python 3 03-13-2011 03:54 PM
Is there any python library that parse c++ source code statically kuangye Python 0 03-13-2011 09:20 AM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Is there a python library to parse C++ code file? Allerdyce.John@gmail.com Python 2 03-17-2006 06:19 PM



Advertisments