成人论坛

Software development - EduqasStages of compilation

Translators like compilers, interpreters and assemblers are needed to translate programs written in high-level languages into the machine code that a computer understands. There are different stages in the compilation process. Tools exist to help programmers develop error-free code.

Part of Computer ScienceUnderstanding Computer Science

Stages of compilation

There are six stages of compiling a program:

  1. lexical analysis
  2. symbol table construction
  3. analysis
  4. semantic analysis
  5. code generation

Lexical analysis

  • Comments and unnecessary spaces are removed.
  • Keywords, and are replaced by 'tokens', which are symbolic to identify what the elements are.

Symbol table construction

  • A table stores the names and addresses of all , constants and .
  • Variables are checked to make sure they have been and to determine the used.

Syntax analysis

  • Tokens are checked to see if they match the syntax of the .
  • If syntax errors are found, error messages are produced.

Semantic analysis

  • Variables are checked to make sure they have been correctly declared and contain the correct data type.
  • Operations are checked to ensure that they are appropriate for the type of variable being used.

Code generation

  • is generated in this stage.

Optimisation

  • Code optimisation makes the program more efficient so it runs faster and uses fewer resources.