Phases of Compiler
The compilation method could be a sequence of different phases. Every phase gets input from its previous stage, has its own representation of source code or program, and feeds its output to subsequent stage or phase of the compiler. Let us delve into the different the phases of a compiler. If you're learning Java course, this blog will be helpful for you understand the different phases of compiler.
- Lexical Analyzer: It typically scans and reads the code like a stream of characters and categorize that sequence of characters into lexemes. After which Java compiler outputs the sequence of tokens in the form of computer readable programing language.
- Syntax Analyzer: The next phase is Syntax analyzer which is also known as parsing. In this phase, the tokens which are generated in the Lexical analyzer are checked for grammar and synchronic linguistics of programing language, whether the expressions are syntactically correct or not. This phase will create the parse or syntax trees as an output.
- Intermediate code generator: It is the third phase which generates a similar intermediate code of the source code. There are several other representations in this phase that generates intermediate code. However TAC (Three Address Code) is the used most widely.
- Code Optimizer: The next phase is optimization of the intermediate codes which are generated in the previous phase. It improves time and space requirement of the program and it eliminates the redundant code present in the program.
- Code generator: This is often the ultimate phase of the compiler during which target code for a specific machine is generated. It performs operations like memory management, Register assignment, and machine-specific optimisation.