Overview of semantic analysis

Semantic analysis ( Semantic the Analysis ) Overview

There are usually two types of statements in the original code: declaration statements and executable statements . For these two types of statements, semantic analysis does different things.

  • Declaration statement: Collect the attribute information of the identifier
  • Executable statement: semantic check

Semantic analysis in statement

Collect the attribute information of the identifier:

  • species
  • Types of
  • Address and length
  • value
  • Scope
  • Parameters and return types

There is a special symbol table ( Symbol Table ) in the semantic analyzer to store the collected attribute information

Why should there be a string table to represent names instead of using strings directly?

Insert picture description here

Semantic analysis of executable sentences

The semantic analysis of executable statements can be roughly understood as the syntax check and automatic adjustment of executable statements. For example: variable names are used without declaration, function parameters do not match

  • Variable or procedure used without declaration
  • Variable or procedure repeated declaration
  • Operation component type does not match,
    just use it
  • Variable or procedure repeated declaration
  • Operation component type does not match
  • Type mismatch between operator and operand

Guess you like

Origin blog.csdn.net/qq_44823898/article/details/108002269