Semantic analysis is a major phase of compiler and interpreter pipelines. It comes after building the abstract syntax tree and before generating intermediate representation.

The core idea is to ensure the program meets the semantic requirements of the language, i.e., whether the abstract syntax tree represents something that can be translated to an actual program. Some example checks:

  • Type checking
  • Validity of operations (for example, is + valid for i32 and f32)
  • Is a variable/function declared already?