Implementing Code Completion and Parsing?

Started by
7 comments, last by nolongerhere 15 years, 1 month ago
As some of you may know, I'm working on a fractal rendering program. I want to let users program their own fractals, so I'm currently working on a programming language translator. Basically I'm defining my own language (which will essentially be a very watered down version of C/C++/C#/Java) which I will then translate into C++ code and then build into a dynamic library. While my language is simple and I only need to translate it instead of compile it, I have no idea where to start. I want my fractal program to come with a simple IDE that meets the below requirements. I don't want it to be a huge IDE with tons of functionality; seeing as the language is simple and the fractals can be programmed without too much code, it would be overkill for it to be a full-fledged IDE.
    IDE Features
  • Code completion/intellisense
  • Real time error checking (like Eclipse for Java)
  • Syntax highlighting
  • And of course, a way to translate the code to C++ (which should require very little translation, seeing as the language will be very similar to C (in syntax))
    Language Features (the syntax is like C, notice how simple the language requirements are)
  • Creation of variables
  • Manipulation of variables (mathematical operations, mostly)
  • Program flow control (loops, conditional statements, etc.)
  • Maybe allow user-defined functions
I just don't know where to start though. Yeah, I could implement all the features with an inefficient, brute force method, but I'm looking for a more elegant solution that doesn't require a lot of hackery. I wouldn't mind taking an existing IDE and chopping off all the fat and modifying it to my needs, but the only IDEs I seem to come across are licensed under the (L)GPL, which I cannot and will not work with. Do you have any tips, pointers, or suggestions that would help me implement this relatively simple IDE? I greatly appreciate any help! [edit] I seem to have forgotten to mention that my GUI and front-end are being programmed in C#, so the IDE would need to be in C# too.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Advertisement
why do you need code completion & intelligence if the language is so simple? keep your requirements smaller & you should be able to bang it out in no time in C#
FTA, my 2D futuristic action MMORPG
Quote:Original post by graveyard filla
why do you need code completion & intelligence if the language is so simple? keep your requirements smaller & you should be able to bang it out in no time in C#

Well, yes, you're right, if it's so simple it really doesn't need code completion/intellisense. The main reason I want to include it is for users who haven't programmed before. I want it to be a user-friendly environment, and if a user isn't exactly familiar with programming, I think it would help to have the code completion. But you do bring up a good point. Maybe I need to rethink this a little and trash the code completion idea.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Eclipse is fairly well adopted in all domains of development. If you're willing to wrap your head around the Eclipse object model, it's possible to develop such plug-ins in a fairly straight-forward manner.

Eclipse in general allows one to model everything, including project, file and language structure, so it goes way beyond just simple suggestion approach. But as an up side, you get the whole 600lb gorilla that is eclipse IDE as a bonus (which may or may not be desirable) with all the other goodies, such as VMS, UI, ....
Quote:Original post by Antheus
Eclipse is fairly well adopted in all domains of development. If you're willing to wrap your head around the Eclipse object model, it's possible to develop such plug-ins in a fairly straight-forward manner.

Eclipse in general allows one to model everything, including project, file and language structure, so it goes way beyond just simple suggestion approach. But as an up side, you get the whole 600lb gorilla that is eclipse IDE as a bonus (which may or may not be desirable) with all the other goodies, such as VMS, UI, ....

Hmmm... Using Eclipse would open a lot of possibilities up, but at the same time I think it would be incredible overkill. I think I'll go with a lightweight approach for the first version, and then gather user feedback to decide if a more robust IDE would be beneficial.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Writing a compiler (or "translator") is no easy task. I would either suggest coding a recursive descent parser in the language of your choice OR use a compiler compiler OR use something such as Boost Spirit. It is a lexical analyzer and parser built in one and it lets you use near-EBNF grammar in actual C++ code, thus making the translation from grammar to code much easier. Before you even choose the tool you use, the best bet would be to write out the full grammar of the language then go from there.

Hope that helps!
Oh and check out my dev journal, I just completed a BASIC to C++ "translator".
From what I understand, NetBeans is easily adaptable/plugin-able. You define your syntax in some for for it and then let other plugins deal with code completion/syntax highlighting.

Not sure if it suits your needs, or just how sane it is. A peer of mine does work in it and recommends it.
Quote:Original post by Falling Sky
Writing a compiler (or "translator") is no easy task.
Fortunately, my language is essentially C++, but without certain features. The language doesn't give the programmer the ability to use templates, bitwise operators, classes/structs (that might change in the future, but for now I can't see why it should), ternary operators, pointers/references, exceptions, and other things. Another difference is that global, predefined variables will be prefixed with '$', and fractal attribute variables are prefixed with '@'. So the only real translating I need to do is add some name-mangling to handle variables starting with '$' or '@'. My biggest challenge is syntax validation (assuming I trash the code-completion idea).

Quote:Original post by Falling Sky
I would either suggest coding a recursive descent parser in the language of your choice OR use a compiler compiler OR use something such as Boost Spirit. It is a lexical analyzer and parser built in one and it lets you use near-EBNF grammar in actual C++ code, thus making the translation from grammar to code much easier.
I've actually spent the day reading through the Boost Spirit docs, and it seems like it would really, really help me. My project's back-end is in C++, so I could easily implement it. The only hesitation I have is the fact that my front-end is in C#, so it would be more elegant to have a C# solution. I'm seriously considering using Boost Spirit though.

Quote:Original post by Falling Sky
Oh and check out my dev journal, I just completed a BASIC to C++ "translator".
Just checked it out, and it looks interesting! I'm going to have to keep track of this project!

Quote:Original post by Telastyn
From what I understand, NetBeans is easily adaptable/plugin-able. You define your syntax in some for for it and then let other plugins deal with code completion/syntax highlighting.

Not sure if it suits your needs, or just how sane it is. A peer of mine does work in it and recommends it.
That sounds pretty neat! I'd like my solution to be more embedded into my program, but I'm going to have to look into that.

What do you guys think of building the translator in C++ with Boost Spirit, and then when the user asks to compile the program in my C# front-end, I start up the translator, tell it which file needs translating, and then have my C# front-end listen to the output from the translator and report it to the user? The translator's output would simply be errors, warnings, and status messages.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Quote:Original post by MikeTacular
Quote:Original post by Falling Sky
Writing a compiler (or "translator") is no easy task.
Fortunately, my language is essentially C++, but without certain features. The language doesn't give the programmer the ability to use templates, bitwise operators, classes/structs (that might change in the future, but for now I can't see why it should), ternary operators, pointers/references, exceptions, and other things. Another difference is that global, predefined variables will be prefixed with '$', and fractal attribute variables are prefixed with '@'. So the only real translating I need to do is add some name-mangling to handle variables starting with '$' or '@'. My biggest challenge is syntax validation (assuming I trash the code-completion idea).


I dont think you understand. Parsing ANY programming language correctly, is no easy task. You say your language is like C++, but I guess you dont realize that C++ in particular is a hard language to parse. The good thing is, it is documented very well. You can even find parsers for C or C++ by googling for it and you could use some of the results as a basis, but I still suggest you start with something easier to parse.

By the way, why are you persistent on C++-like syntax? You mentioned you want non programmers to beable to use it yet your picking a not so easy language to use and a not so easy language to parse.

EDIT: Fixed the quotes

This topic is closed to new replies.

Advertisement