What are the phases of Compiler?

Overview

Compiler converts the high-level language into a low-level language. Assembler converts the low-level language into machine understandable language, like bits of 1’s and 0’s.

  • The preprocessor attaches the predefined library file or global variables to the source program and removes the comment lines while the compilation processes. The translated programs are saved in secondary storage.
  • When we execute the program, the file is brought from secondary storage to main memory, known as loading.

Phases of Compiler

  1. Lexical Analysis: The lexical analyzer is responsible for reading the code line by line. Whenever it reads a word, it checks if the word is a keyword or not using a symbol table and generates a token for that particular word. The lexical analysis removes blank spaces, argument lines, the next line character, and braces: <Token_name,number>

  2. Syntax Analysis: It takes tokens produced by the lexical analyzer as input and generates a parse tree.

  3. Semantic Analysis: It verifies the parse tree, and any errors found are notified to the error handler.

  4. Intermediate code Generation: It represents the final machine language code produced. It mainly bridges both the analysis and synthesis phases together.

  5. Code Optimizer: This is an optional step in which the code could be reduced to optimize the code size, space, and access.

  6. Code Generation: It translates intermediate code into a sequence of a relocatable machine code.

Block diagram

Phases of a compiler

Free Resources