Chapter 2: Introduction to compilers

Semantic Analysis

. Too hard for compilers. They do not have capabilities similar to human understanding

. However, compilers do perform analysis to understand the meaning and catch inconsistencies

. Programming languages define strict rules to avoid such ambiguities

 

{ int Amit = 3;

{ int Amit = 4;

cout << Amit;

}

}

Since it is too hard for a compiler to do semantic analysis, the programming languages define strict rules to avoid ambiguities and make the analysis easier. In the code written above, there is a clear demarcation between the two instances of Amit. This has been done by putting one outside the scope of other so that the compiler knows that these two Amit are different by the virtue of their different scopes.