Is it possible to call C # lexical / parsers without compilation?

Given this question SO, where is the entire C # compiler in memory invoked. If only lexical and parsing analysis is required: analyze the text as a stream of tokens, check them and exit.

Is this possible in the current version of System.CodeDom.Compiler , if not - will it be?

+4
c # lexical-analysis codedom compiler-as-a-service
source share
2 answers

If you can use Mono, I suppose it has C # parser / lexer that you can use.

Here is the link to look at. As for the MS C # team that we plan to do, there is some talk about making the C # compiler a β€œservice” at some point, but it is not clear what this means or when it will happen.

+6
source share

Although the code may seem to be compiled in memory (CompilerParameters.GenerateInMemory), this is not what is actually happening. The same compiler as in Visual Studio is used to compile the code (csc.exe). It starts with CreateProcess (like Process.Start) and runs outside the process to compile assembly code on disk in a temporary folder. The GenerateInMemory parameter calls Assembly.LoadFrom () to load the assembly.

You will get the equivalent of syntax checking by simply setting GenerateInMemory to false and removing OutputAssembly after it is completed.

Although this may seem to be the opposite, the huge benefit is that it will not affect your process. This will delay you until C # 5.0 leaves.

+1
source share

All Articles