PDA

View Full Version : Develop C++ IDE



mvbhavsar
28th March 2011, 08:16
I am working on IDE which will write C++ code in editor. I have advanced quite but has facing problems of showing functions, variables or any other declarations in popup list while typing in text editor from header files. This will be exactly like we declares a method in .h file QT and while implementing in .cpp we type dot key and gets its details in list box.

stampede
28th March 2011, 09:00
And what's your problem exactly ? You don't know how to create a list of all variables available in the current scope of the cursor ? This doesn't surprise me, you'll need to write a kind of C++ grammar parser for that ;)
Suppose that user writes

#include <iostream>
After the file is saved, a good IDE should now parse the included file and extract all available classes, symbols and methods (if its not done already). Writing such editor is not trivial task, for example, imagine an user writing an implementation of a method. Depending on the cursor position, you'll need to provide different lists of available variables:


void MyClass::method(){
int x, y;
//pos1 - all symbols from global scope, MyClass scope, and variables x,y
{
#ifdef SYMBOL_1
int scopedVar;
// pos2 - all symbols from pos1 and scopedVar, but only if SYMBOL_1 is defined !
...
#else
...
#endif
}
}

Ok, but what was your question anyway ?

mvbhavsar
28th March 2011, 09:05
The question is how do I get list of functions and variables from header file. I know how to populate in list and show whenever dot key is pressed. I was just checking if there is any methodology to parse header file to list its contents.:)

stampede
28th March 2011, 09:41
If you want to have full list, you won't escape writing a kind of C++ preprocessor, because some variables (or even whole classes) can be declared using some of its features, like macro expansion or new line splitting.
Next thing is parse the C++ code itself - you need to be familiar with context free grammars (http://en.wikipedia.org/wiki/Context-free_grammars). Parsing C++ code is a really tough task if you ask me.
Try to google for "writing a C++ parser" or something like that, and see for yourself.
In your case it could be easier than a "real" C++ parser, because you don't really have to care about syntax errors in general, as you are only interested in declarations - but a good IDE will warn about syntax errors as well :)
I don't really know how to help you, try to use google, maybe you can find some code samples or something.

wysota
28th March 2011, 10:03
You can get away with some of the work by using ctags (ctags.sourceforge.net).

Zlatomir
28th March 2011, 12:08
Or maybe you can get inspiration from Qt Creator, since it's open source, here is a link to Qt Creator 2.1 source (http://qt.nokia.com/downloads/qt-creator-source-package)

wysota
28th March 2011, 12:39
Or you can drop your project and instead extend QtCreator. Many people would benefit from that.

squidge
28th March 2011, 13:13
What you need to ask yourself is "Does anyone want yet another C++ editor?". There are lots of editors already out there, why do want to put the time and effort into something that has already been done multiple times?

For example, Qt Creator does what you want and is free.
Netbeans does what you want and is free, cross platform, and multi language.
CodeLite does what you want and is free.
Visual Studio Express does what you want and is free.
etc...

If you want specific features that other editors don't have, then implement them via plugins. No need to write yet another editor from scratch.

stampede
28th March 2011, 18:16
why do want to put the time and effort into something that has already been done multiple times?
I second that. Writing yet another text/code editor makes very little sense.
But if you simply enjoy doing it and/or you feel that you can learn a lot, then just do it.

What you need to ask yourself is "Does anyone want yet another C++ editor?"
Correct. And continue with your project if the answer is "Yes, I want it".