Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
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
Posted
Comments
Sergey Alexandrovich Kryukov 15-Apr-11 13:00pm    
This is pretty interesting question, thanks for asking. My 5.
--SA

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
 
Share this answer
 
Comments
M.CHAITHANYA 15-Apr-11 4:26am    
Hi Manfred,

Who does this ?like is there any program that monitors the code and give suggestions.?
Manfred Rudolf Bihy 15-Apr-11 4:53am    
Simply put is it a part of the VS IDE program. It monitors if changes were made to the source code and when a certain threshold of changes has been made the source code is parsed (AST) and the result is analyzed.
Sergey Alexandrovich Kryukov 15-Apr-11 5:20am    
This is basically what happens, my 5.
As to the detail of how it works -- please see my Answer.

Teamwork again?
--SA
Sandeep Mewara 15-Apr-11 5:56am    
Lots of tagging for you... ;) Great work!

I am a lot busy these days... :( meeting & meetings.
Sandeep Mewara 15-Apr-11 5:56am    
My 5 Manfred! :)
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
 
Share this answer
 
Comments
Sandeep Mewara 15-Apr-11 5:56am    
My 5 SA! :)
Sandeep Mewara 15-Apr-11 5:57am    
Wanted to know the deeper details myself... thanks for sharing.
Sergey Alexandrovich Kryukov 15-Apr-11 12:59pm    
Thank you, Sandeep.
--SA
Manfred Rudolf Bihy 15-Apr-11 6:30am    
I'm not sure SA if it is really a full blown compile, I thought more about AST generation and some analysis thereof. If you have more information about the inner workings of VS IDE's syntax check mechanism please share it with us!

Still a 5+!
Sergey Alexandrovich Kryukov 15-Apr-11 12:59pm    
Thank you, Manfred.
I never pretended (and I could not) this is a full blown compile/build as it is done in VS; this is rather a point of view of a maker of a home-baked IDE. For OP is could be quite interesting due to his purely educational motivation (which is a very good thing)...
--SA

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