/    /  Compiler Design-Phases of a Compiler

Phases of a Compiler

 

There are 6 phases in a compiler

 

  • The Lexical Analyzer is fed with a high-level language. Here the code is divided into a series of tokens. Tokens are a set of characters or lines

 

  • Syntax Analyzer is also called the parse. The stream of tokens, Grammar rules are given as the input to the syntax analyzer. Based on these inputs, it generates a Parse Tree. It also analyses if the structure, the keywords and everything related to the syntax of the program are correct. 

 

  • The semantic analyzer gets the parse tree as the input. It checks for type casting errors or semantic errors. 

 

  • In intermediate code converts expressions into 3 address code formats. 

 

  • Code optimization tries to remove unnecessary variables. Code optimization helps to reduce execution time and reduce the storage space that variables occupy.

 

  • The input is the optimized code. The values in the expression are moved to special-purpose registers to perform operations faster.

 

 

Reference Link

Phases of a Compiler