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

K

kuangye

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.
 
Ö

Öö Tiib

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.
 
K

kuangye

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.
 
G

Gert-Jan de Vos

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.
 
P

Puppet_Sock

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
 
T

tm

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top