c#应用程序作为"c"编辑器 [英] c# application as a 'c' editor

查看:122
本文介绍了c#应用程序作为"c"编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#.net设计一个"C"编辑器.

我想在程序中使用编译器.

我的应用程序将提供一个键入c代码的环境,然后,通过单击菜单栏中的一个选项,它将编译代码并显示输出.

我该如何实现呢?

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?

推荐答案

您有可用于此目的的C编译器吗?如果没有,请尝试一个:Google的开源C编译器"或自己编写-大量的工作.

然后将程序另存为特定文件,并使用Process.Start运行编译器,在命令行中将该文件作为输入,并捕获标准输出:
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:
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();


怪异,我最近回答了几乎相同的问题.请参阅:
在IDE中提供了COMPILER,DEBUGGER功能 [ ^ ].

现在,你能告诉我,什么,你们都是同一所学校的同一作业?! :)

祝你好运,
—SA
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


请自己尝试编码.我会给你逻辑.

制作编辑器需要您做很多工作.
1)需要富文本框.您的文本框(发生实际编码的地方)应该能够识别代码段的字体颜色.
2)您需要放入语法和语法解析器(如果它是高级编辑器).在编译代码之前会发出警告.
3)编译代码时,将使用DOS命令(tcc文件名-选项),您需要开发一种机制来在C#UI上显示编译输出. (您需要将DOS编译器的输出收集到一些文本文件中,然后在UI上显示).
4)调试部分是最困难的部分.您需要设计断点处理技术和手表.

首先从一些基础开始项目,然后讨论您遇到的困难;)

真是太幸运了.
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.


这篇关于c#应用程序作为"c"编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆