Click here to Skip to main content
15,882,114 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am designing a 'C' editor using c#.net.

I want to use a compiler within the program.

My application will provide an environment to type c code then, by clicking on an option in a menu bar, it will compile the code and display the output.

How can I achieve this?
Posted
Updated 17-Feb-11 21:36pm
v2
Comments
R. Giskard Reventlov 18-Feb-11 3:35am    
What have you already tried? I'm always amused by someone taking on a project where they have no idea how parts of it should work then expect someone else to bail them out.
Wild-Programmer 18-Feb-11 3:42am    
LOL :D
so many people get scolded for this, still no effect.

Do you have a C compiler you can use for this? If not, go get one: Google for "open Source C Compiler" or write your own - lots of work.

Then save your program as a specific file, and use Process.Start to run the compiler, giving the file as the input on the command line, and catching the standard output:
C#
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "MyCCompiler.exe";
p.Arguments = myFileName + " " + myCompilerArguments;
p.Start();
string results = p.StandardOutput.ReadToEnd();
p.WaitForExit();
 
Share this answer
 
Comments
Olivier Levrey 18-Feb-11 3:53am    
Voted 5 as well. I hope OP won't decide to write his own compiler, otherwise the forum will soon be overloaded!!
OriginalGriff 18-Feb-11 4:00am    
It's not that big a job for "just C": there are a lot of examples and help out there.
It's a big job to do well though!

I think just the editor bit will be enough trouble: I wouldn't want to duplicate PSPAD in a hurry :laugh:
Sharad Kawale 22-Feb-11 9:42am    
Hello sir,

now i m able to run a .exe file through my c#.net application...
now i need a readymade open source .exe 'c' compiler..

so can u plz suggest me few names of them so that i can google 4 them???
actually i googled a lot but ended with nothing in hand....

thanx 4 ur previous help,,,
again hoping ur kind attention,,

plz, do reply..
OriginalGriff 22-Feb-11 9:47am    
Try Watcom: it also supports C++ as and when you upgrade your app!
http://www.openwatcom.org/index.php/Main_Page
Manfred Rudolf Bihy 18-Feb-11 4:25am    
Good answer, 5
Weird, I recently answered nearly identical question. Please see:
providing COMPILER, DEBUGGER facility in IDE[^].

Now, will you tell me, what, you all are from the same school getting identical assignments?! :)

Good luck,
—SA
 
Share this answer
 
Comments
Olivier Levrey 18-Feb-11 3:50am    
Voted 5.
Sergey Alexandrovich Kryukov 18-Feb-11 13:28pm    
Thank you.
--SA
Sharad Kawale 18-Feb-11 3:58am    
thank you sir,
Sergey Alexandrovich Kryukov 18-Feb-11 13:28pm    
You're welcome.
Thank you for accepting my anwer.
--SA
Sharad Kawale 22-Feb-11 9:41am    
Hello sir,

now i m able to run a .exe file through my c#.net application...
now i need a readymade open source .exe 'c' compiler..

so can u plz suggest me few names of them so that i can google 4 them???
actually i googled a lot but ended with nothing in hand....

thanx 4 ur previous help,,,
again hoping ur kind attention,,

plz, do reply..
Try the coding yourself. I will give you the logic.

Making a editor will require you to do a lot of work.
1) Rich textbox required. Your textbox (where actual coding happens) should be able to identify font colors for code snippets.
2) You need to put in grammar and syntax parser (if it is a high level editor). It will give warning before code compilation.
3) While compiling code you will use DOS command (tcc filename - options), you need to develop mechanism to show the compilation output on C# UI. (You need to collect the DOS compiler output in some text file and then show it on UI).
4) Debugging part is the most difficult one. You need to design breakpoint handling techniques and watches.

Start the project first with some base and then discuss where you are stuck ;)

Goooooood luck.
 
Share this answer
 
Comments
Sharad Kawale 18-Feb-11 3:57am    
thank you, sir...
Wild-Programmer 18-Feb-11 4:08am    
My pleasure :)
Sharad Kawale 22-Feb-11 9:41am    
Hello sir,

now i m able to run a .exe file through my c#.net application...
now i need a readymade open source .exe 'c' compiler..

so can u plz suggest me few names of them so that i can google 4 them???
actually i googled a lot but ended with nothing in hand....

thanx 4 ur previous help,,,
again hoping ur kind attention,,

plz, do reply..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900