First you need to understand what parsing is and what abstract syntax trees are. To do this, you can go to Wikipedia about abstract syntax trees for a quick glance.
You really need to spend some time on the compiler to understand how abstract syntax trees are related to parsing and can be created on parsing; the classic reference is Aho / Ullman / Sethi's book Compilers (easy to find on the Internet). You can find the SO answer to Are there any "funny" words? ways to learn about languages, grammars, analyzes and compilers? Instructive.
Once you understand how to build an AST for simple grammar, you can turn your attention to something like C #. The problem here is large-scale; It's one thing to play with a toy language with 20 grammar rules. Another thing is to work with grammar in a few hundred or thousand rules. The experience will be small, it will greatly facilitate the understanding of how large are united, and how to live with them.
You probably don't want to create your own C # grammar (or implement it according to the C # standard); its quite a lot of work. You can get affordable tools that will give you the C # AST (Roslyn already mentioned, ANTLR has a C # parser, there are many more).
It is true that you can use AST to highlight syntax (although this probably kills the mosquito with a sledgehammer). What most people think little (but the compiler books emphasize) is what happens after you have AST; basically they are not useful on their own. You really need a lot more technique to do something interesting. Instead of repeating it over and over (I constantly see the same questions), you can see my discussion of Life After Parsing for more details.
Ira Baxter
source share