Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: [Caml-list] C++ parser

22 views
Skip to first unread message

Yoann Padioleau

unread,
Jan 14, 2010, 11:49:46 PM1/14/10
to Kihong Heo, caml users, Cocci List

On Jan 14, 2010, at 3:36 AM, Kihong Heo wrote:

>
> Dear all.

Hi,

>
> Is there anybody knowing about existing C++ parser that is not so big?
>
> I've already know EDG and ELSA.
> But they are so big and hard to see.
> I don't want a perfect C++ parser.
> If it can parse common and simple C++, that's OK.

There is one here:
http://padator.org/software/project-yacfe/yacfe-light-0.3.tgz
but it's not really complete.
Once built, you can test it with
./yacfe -parse_c++ foo.cpp

>
> I need your advice.
>
> Thank you.
> --
> Kihong Heo.
>
>
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Phil Tomson

unread,
Jan 15, 2010, 1:35:45 PM1/15/10
to
On Jan 14, 8:49 pm, Yoann Padioleau <pada...@wanadoo.fr> wrote:
> On Jan 14, 2010, at 3:36 AM, Kihong Heo wrote:
>
>
>
> > Dear all.
>
> Hi,
>
>
>
> > Is there anybody knowing about existing C++ parser that is not so big?
>
> > I've already know EDG and ELSA.
> > But they are so big and hard to see.
> > I don't want a perfect C++ parser.
> > If it can parse common and simple C++, that's OK.
>
> There is one here:
> http://padator.org/software/project-yacfe/yacfe-light-0.3.tgz
> but it's not really complete.
> Once built, you can test it with
> ./yacfe -parse_c++ foo.cpp

There's clang which is part of the LLVM project. Not sure how easy/
hard it is to use. I'd guess most any parser that could parse C++
would be "big" and probably difficult to use... clang's C++ support
isn't complete yet (is any C++ parser complete?), but they do seem to
be making progress and it's probably about on par with ELSA.
http://clang.llvm.org/

Guillaume Yziquel

unread,
Jan 17, 2010, 11:16:33 AM1/17/10
to Kihong Heo, caml...@inria.fr
Kihong Heo a écrit :
> Dear all.

>
> Is there anybody knowing about existing C++ parser that is not so big?
>
> I've already know EDG and ELSA.
> But they are so big and hard to see.
> I don't want a perfect C++ parser.
> If it can parse common and simple C++, that's OK.

The perfect C++ parser: GCC XML. I thing that there is an OCaml binding
to it.

Otherwise, depending on what you want to do, there is Swig. It parses
only C++ declarations.

> I need your advice.

For a new project, I'd use GCC XML.

> Thank you.
> --
> Kihong Heo.

All the best,

--
Guillaume Yziquel
http://yziquel.homelinux.org/

Basile STARYNKEVITCH

unread,
Jan 17, 2010, 2:15:50 PM1/17/10
to guillaum...@citycable.ch, caml...@inria.fr
Guillaume Yziquel wrote:
>
> For a new project, I'd use GCC XML.

[[sorry for this reply, which is barely related to Ocaml, but may be of interest to several Ocaml fans interested in C++
analysis]]

There is however a small caveat. AFAIK, GCC XML is not much maintained, and depends upon an old GCC version (but I might
be wrong on both points). Latest release of GCC XML seems to be 0.6 from february 2004.

Next (4.5.0) release of GCC will provide two major new features: link time optimization [=LTO] & plugins.

Both features are useful for any kind of C++ static analysis programs; a plugin can define new passes, and the LTO
feature enable them to be run at "link" time, that is to merge information from several compilation units. And indeed
GCC have powerful & common internal representations of the compiled source code, which is the same for C, C++, Fortran,
Ada, Java .. source inputs to GCC.

So one could consider coding a plugin for GCC which extracts the exact information required by your (Ocaml) static
analyser. In addition (sorry for the shameless self-promotion), if you like functional programming, you might even code
your plugin as a MELT module. MELT is a plugin (written by me) which enables you to express your GCC pass in a
higher-level Lisp-like mostly dynamic language (with closures, powerful pattern matching [in particular pattern matching
on GCC internal representations like Gimple], objects - but unfortunately no static typing with type inference).

Feel free to ask me more (preferably off list, or preferably on the g...@gcc.gnu.org list) about MELT.

Regards.

--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

Yoann Padioleau

unread,
Jan 17, 2010, 2:16:34 PM1/17/10
to guillaum...@citycable.ch, caml...@inria.fr

On Jan 17, 2010, at 8:16 AM, Guillaume Yziquel wrote:

>
> Kihong Heo a �crit :


>> Dear all.
>> Is there anybody knowing about existing C++ parser that is not so big?
>> I've already know EDG and ELSA.
>> But they are so big and hard to see. I don't want a perfect C++ parser.
>> If it can parse common and simple C++, that's OK.
>
> The perfect C++ parser: GCC XML.

From the FAQ they say:
"Why are C++ function bodies not dumped in XML?
The original sponsors of the project had no need for function bodies. So far the authors have not had time or funding to implement the support. Contact the mailing list if you are interested in contributing this support or providing funding to have it implemented. "

is it still true ?

Also do they maintain comments, space, positions, cpp directives ?
If you need to do source-to-source transformation, e.g. refactoring,
you need those things.



> I thing that there is an OCaml binding to it.
>

is it this one?:
http://qt-caml.crapulion.org/trac/browser/trunk/src/gccxml/lib

0 new messages