Goseeko blog

What is the Phases of Compiler?

by Bhumika

The method of compilation includes the sequence of different stages. Each phases of compiler takes a source programme in one representation and produces output in another representation. On the other hand, From its previous stage, each process takes input. 

Phases of Compiler

The various phases of the compiler take place :

  • Lexical Analysis
  • Syntax Analysis
  • Semantic Analysis
  • Intermediate Code Generation
  • Code Optimization
  • Code Generation 

Lexical Analysis :

The first phase of the compilation process is the lexical analyzer phase. As input, it takes source code. Moreover, One character at a time, it reads the source programme and translates it into meaningful lexemes. Furthermore, These lexemes are interpreted in the form of tokens by the Lexical analyzer. 

Syntax Analysis :

Syntax analysis is the second step of the method of compilation. On the other hand, Tokens is require as input and a parse tree is generated as output. In addition, The parser verifies that the expression made by the tokens is syntactically right or not in the syntax analysis process.

Semantic Analysis :

The third step of the method of compilation is semantic analysis. Furthermore, This tests whether the parse tree complies with language rules. In addition, The semantic analyzer keeps track of identifiers, forms, and expressions of identifiers. The output step of semantic analysis is the syntax of the annotated tree. 

Intermediate Code Generation :

The compiler generates the source code into an intermediate code during the intermediate code generation process. Between high-level language and machine language, intermediate code is created. Moreover, You can produce the intermediate code in such a way that you can convert it easily into the code of the target computer.

Code Optimization :

An optional step is code optimization. It is use to enhance the intermediate code so that the program’s output can run quicker and take up less space. Furthermore, It eliminates redundant code lines and arranges the sequence of statements to speed up the execution of the programme.

Code Generation :

The final stage of the compilation process is code generation. Furthermore, It takes as its input the optimized intermediate code and maps it to the language of the target computer. Moreover, The code generator converts the intermediate code to the required computer’s machine code.

Interested in learning about similar topics? Here are a few hand-picked blogs for you!

You may also like