From: Sam Roberts Date: 2003-04-27T23:06:01+09:00 Subject: Re: Parsing C++ with Ruby Quoteing deliriousNOSPAM@atchoo.be, on Sun, Apr 27, 2003 at 07:52:39PM +0900: > On Sat, 26 Apr 2003 at 16:48 GMT, Sam Roberts wrote: > > A recent Dr. Dobbs Journal described extensions made to gcc so that it > > dumps the parsed c or c++ syntax as xml. They did this because existing > > non-compiler parsers were all aproximations of the c++ syntax, and > > didnt' work with complex templated c++ code. They used it to build > > wrappers in some other language (swig-like), but you could use this to > > get an xml representation of the code, and then your dotfile generator > > would only have to parse xml, for which there are many tools. > > I had never heard about this, very interesting. > > Am I to gather from your answer that you do not recommend trying to > match multi-line C++ expressions with Ruby. I haven't coded in C++ in years, but I tried to write a parser for it once, and things like this are hard to parse: template > > Foo(T t, int max = 19); Even if it wasn't hard, there's no way it would be as easy to parse as xml, where there are lots of mature toolkits. Say it "only" takes you 10 hours... thats 10 hours you could have spent doing something cool thats never been done before! From gccxml.org: Development tools that work with programming languages benefit from their ability to understand the code with which they work at a level comparable to a compiler. C++ has become a popular and powerful language, but parsing it is a very challenging problem. This has discouraged the development of tools meant to work directly with the language. There is one open-source C++ parser, the C++ front-end to GCC, which is currently able to deal with the language in its entirety. The purpose of the GCC-XML extension is to generate an XML description of a C++ program from GCC's internal representation. Since XML is easy to parse, other development tools will be able to work with C++ programs without the burden of a complicated C++ parser.