Chapter 2: Introduction to compilers

Semantic Analysis

 

. Check semantics
. Error reporting
. Disambiguate overloaded operators
.Type coercion
. Static checking

- Type checking

- Control flow checking

- Unique ness checking

- Name checks

 

Semantic analysis should ensure that the code is unambiguous. Also it should do the type checking wherever needed. Ex. int y = "Hi"; should generate an error. Type coercion can be explained by the following example:- int y = 5.6 + 1; The actual value of y used will be 6 since it is an integer. The compiler knows that since y is an instance of an integer it cannot have the value of 6.6 so it down-casts its value to the greatest integer less than 6.6. This is called type coercion.