- Roslyn Cookbook
- Manish Vasani
- 142字
- 2021-07-15 17:07:32
Creating a syntax tree analyzer to analyze the source file and report syntax issues
A syntax tree analyzer registers action callbacks to analyze the syntax/grammar for the source file and reports pure syntactic issues. For example, a missing semicolon at the end of a statement is a syntactic error, while assigning an incompatible type to a symbol with no possible type conversion is a semantic error.
In this section, we will write a syntax tree analyzer that analyzes all the statements in a source file and generates a syntax warning for any statement that is not enclosed in a block, that is curly braces { and }. For example, the following code will generate a warning for both the if statement and the System.Console.WriteLine invocation statement, but the while statement is not flagged:
void Method()
{
while (...)
if (...)
System.Console.WriteLine(value);
}
推薦閱讀
- 零基礎(chǔ)學(xué)Visual C++第3版
- Learning Chef
- 數(shù)據(jù)結(jié)構(gòu)和算法基礎(chǔ)(Java語言實(shí)現(xiàn))
- Interactive Data Visualization with Python
- Mastering QGIS
- 網(wǎng)絡(luò)爬蟲原理與實(shí)踐:基于C#語言
- Hands-On Natural Language Processing with Python
- Learning Apache Cassandra
- Android移動開發(fā)案例教程:基于Android Studio開發(fā)環(huán)境
- Java Web從入門到精通(第3版)
- 零代碼實(shí)戰(zhàn):企業(yè)級應(yīng)用搭建與案例詳解
- Java程序設(shè)計(jì)實(shí)用教程(第2版)
- Microsoft HoloLens By Example
- 計(jì)算思維與Python編程
- Mastering Machine Learning with scikit-learn