What Is The Phases of Compiler
What Is The Phases of Compiler
A compiler is a computer program that decodes computer code composed in one programming
language into another language. Or we can say that the compiler helps in translating the source
code composed in a high-level programming language into the machine code. You can also dive
deep into the difference between Compiler and Interpreter to get more familiar with this topic.
1. Lexical Analysis
2. Syntactic Analysis or Parsing
3. Semantic Analysis
4. Intermediate Code Generation
5. Code Optimization
6. Code Generation
1.Lexical Analysis: Lexical analysis or Lexical analyzer is the initial stage or phase of the compiler.
This phase scans the source code and transforms the input program into a series of a token.
A token is basically the arrangement of characters that defines a unit of information in the source
code.
NOTE: In computer science, a program that executes the process of lexical analysis is called a
scanner, tokenizer, or lexer.
You can gain in-depth knowledge of lexical analysis to get a better understanding.
It accepts tokens as input and provides a parse tree as output. It is also known as parsing in a
compiler.
Roles and Responsibilities of Syntax Analyzer
A code that is neither high-level nor machine code, but a middle-level code is an
intermediate code.
We can translate this code to machine code later.
This stage serves as a bridge or way from analysis to synthesis.