编写代码时显示错误-是编译器runnnig在幕后 [英] Error's shown While Writing Code-Is complier runnnig Behind the scenes

查看:66
本文介绍了编写代码时显示错误-是编译器runnnig在幕后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我们编写一些不正确的Synatx代码时,Visual Studio建议使用红色标记,表明语法错误,并且代码需要检出.这时.编译器是否在后台运行?



问候
Chaithanya M

Hi Everyone,

When we write some code of incorrect synatx,Visual studio suggests with a Red mark which tells that syntax is wrong and code need to checked out.At this time..Is the compiler running behind the scenes?



Regards
Chaithanya M

推荐答案

它没有完成完整的编译过程,因为这将需要代码生成,但是是的,当您进行更改时,将对正在编辑的源进行解析它,并对生成的语法树进行一些分析.类似于检查您正在使用的变量是否已经声明,类型是否兼容以及是否将方法调用的用法与该方法的可用签名相匹配.因此,是的,当您使用VS编辑代码时,幕后发生了很多事情.

希望我能澄清您的问题!

快乐的编码(和编辑;))!

-MRB
It isn''t doing a complete compilation process as this would require code generation, but yes the source being edited is parsed while you''re changing it and some analysis is done on the resulting syntax tree. Like checks if a variable you are using has already been declared, if types are compatible and matching the usage of a method call with the available signatures for that method. So yes there is quite a lot going on behind the scenes when you are using VS to edit your codes.

I hope I could clarify your issue!

Happy coding (and editing ;) )!

-MRB


编译器在给定时刻可能正在运行,也可能未运行.我可以在显示警告和错误的同时运行.编译器通常是普通的控制台应用程序.您甚至可以自己创建此效果.

IDE使用System.Diagnostic.Process将编译器作为外部进程运行,但是标准控制台输出重定向到两个单独的流(stdoutstderr). IDE实现了特殊的流类型;主机(IDE)进程中有一个单独的线程从流中读取行,并将其重定向到UI(可以通过Dispatcher.InvokeDispatcher.BeginInvoke完成.这样,UI可以显示警告/错误,而编译器仍在工作,UI始终保持响应状态.

我过去曾详细解释过如何做到这一点.答案:
如何从命令提示符中读取 [
Compiler may or may not be running it any given moment. I can run while showing warnings and errors. The compiler is usually a normal console application. You can even create this effect yourself.

IDE is running a compiler as an external process using System.Diagnostic.Process, but the standard console output is redirected to two separate streams (stdout and stderr). IDE implements special stream type; a separate thread(s) in the host (IDE) process reads the line from the streams as they appear and redirect the lines to UI (it can be done via Dispatcher.Invoke or Dispatcher.BeginInvoke. In this way, the UI can show warnings/error while the compiler is still working, with the UI remaining responsive all the time.

I explained how to do it in detail in my past Answer:
How to read from command prompt[^].

—SA


这篇关于编写代码时显示错误-是编译器runnnig在幕后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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