Bruintje Beer wrote:
Hi,
Can someone give some hint how to build a code completion parser in C++
John
Hehe, that is not a simple task, because it has two solutions, both are
bad:
- implement "correct" parser, basically a C++ frontend. This has
significant disadvantage that you will have to wait a couple of seconds
before completion list opens
- implement "heurestic" (read "cheating") parser. Disadvantage is that
it will not be 100% correct
The main purpose of "cheating" is to somehow avoid #include directives,
because this is what makes it slow. Of course, another purpose is to
make the parser simpler, you will want to skip the code you do not
need, e.g. expressions.
Well, enough theory, we implemented one for U++ (
www.ultimatepp.org).
In the end, it is quite simple, about 2000 lines. It uses global symbol
database to avoid #include problem. If you are interested, download
U++, open uppsrc/ide project and see CppBase package. Current drawback
is that it does not expand macros, something to fix in next release.
Also, Eclipse and KDevelop contain parsers, you can most likely see
what is going on there as well.
Another project is here
http://www.cs.berkeley.edu/~smcpeak/elkhound/
and it also contains many links to related sites.
Mirek