PDA

View Full Version : Parser



ComaWhite
28th October 2008, 12:06
Is there a good parser/lexer that generates valid C++ code because all I've found was just C ones and I don't want to rely on dependencies like antlr does with java . And has good cross-platform support? and well documented?

fullmetalcoder
28th October 2008, 14:19
Are you looking for a parser, a parser generator or a code generator ? (your question is not clear about that...)

Writing a fully correct parser for C++ is *extremely hard*, if possible at all. However if you only need to understand a subset of C++, or to extract for some pieces of data (for, e.g, class browsing) it is doable. Depends on your requirement really.

Some potentially useful references :

A parser GLR generator, which comes with a C++ parser generated with it (claims to fully parse Qt and Mozilla sources among other things) : http://www.cs.berkeley.edu/~smcpeak/elkhound/
Ctags parses C and derived languages (which includes C++) http://ctags.sf.net


I've written some C++ parsers myself but they don't qualify as full parsers : they were either just lexers (for syntax highlighting) or permissive extractors (for code browsing and code completion)

travis
28th October 2008, 15:15
Using ANTLR one can choose target language as C++/Python etc.

ComaWhite
28th October 2008, 22:03
Sorry. I wanted to write a little basic scripting language in C++.

wysota
28th October 2008, 23:22
So you want a parser generator :) Apart from sources already given you can search for bison or qlalr (the latter if you use Qt).