Anonymous

Why Do We Divide Compiler Into Different Phases? Explain The Different Phases Of Compiler?

4

4 Answers

Amen Bukhari Profile
Amen Bukhari answered
Compiler is large and complex program so we divide compiler into different phases on the base of their complexity. There are four compulsory phases of complier; Lexical Analysis, Syntax Analysis, Semantic Analysis and Target Code Generation. In first phase of compiler we define lexical rules by regular expression. Lexical Analysis is also called Scanning. In this phase source program is checked to have valid characters and words. After detail analysis input stream of tokens are stored in a buffer. The second phase of compiler is Syntax Analysis. In this phase we define syntax rules by Context Free Grammar. Syntax Analysis is also called parser. During parsing, syntax rules are checked. Input of this phase is tokens and output is parse tree or syntax tree. Third phase of complier is Semantic Analysis. Basically the word semantic means the "meaning".

In this phase we define semantic rules by attribute grammars. Semantic Analysis has two types; Declaration Checking and Type Checking. The input of this phase is syntax tree and output is attribute grammar. The last and final phase is Target Code Generation. After analysis of source code is completed, then last step is converting it into target language. The other optional phases are Source Code Optimizer, Target Code Optimizer and Intermediate Code Generator
Anonymous Profile
Anonymous answered
Semantic means the "meaning".

In this phase we define semantic rules by attribute grammars. Semantic Analysis has two types; Declaration Checking and Type Checking. The input of this phase is syntax tree and output is attribute grammar. The last and final phase is Target Code Generation. After analysis of source code is completed, then last step is converting it into target language. The other optional phases are Source
Amen Bukhari Profile
Amen Bukhari answered
For performing different task on the computer, compiler is communication medium that translate source language into target language. Compiler allows the user to perform customized task on machine. Initially for writing compiler machine language was used. After some development assembly language and these days high level language are used for writing compiler. There are different types of compiler; General Complier, Just in Time Compiler, Native Code Compiler, Cross Compiler, Source to source Compiler, Multi-Pass Compiler, Single-Pass Compiler etc. General compilers are traditional compilers. These compliers use assembler.

Just in Time Complier takes source code as input and executes machine language. Example of this compiler is Java Virtual Machine. Often byte code us used as intermediate representation. In Native Code Compliers both complier and target runs on the same machine. In Cross Compiler, compiler runs on different machine and target code runs on different machine. In Source to Source Compiler input is High Level language and output is also a High Level language. For example C++ to C compiler. Multi-Pass Compiler runs the compiler from starting phase to finishing phase separately. Each phase after compilation writes its output to the disk file. Single-Pass Compiler reads the source code only once. In this type of Compiler Syntax analyzer uses Lexical Analysis and Code Generation as subroutines.
Anonymous Profile
Anonymous answered
Define phases of compilation cycle

Answer Question

Anonymous