Hello Viewer! Before we start learning computer languages we have to know the concept of a compiler, an interpreter, loader, linker, editor etc.
So, let's start with Compiler...
Compiler
A compiler is a program that translates a high-level language program into low-level language program.so basically compiler is a "Translator". whose source language is high-level language and the target language is low-level language.
- A compiler is used to implement a high-level language.
- It is a System Software.
- High-level language considers as Programming Language and low-level language considers as Machine language.
Why we Study Compiler?
- For large scale application development.
Example: Big programming project
- For programming language research.
- Many application has similar properties to one or more phase of compiler and tools can help an application program working on another project besides compiler.
- For Automata theory.
Component of Compiler
A compiler composed of several components also called "Phases" each phases performing a specific task.
A complete compilation procedure can be divided into six phases and these phases are regroup in two parts:-
PART I
(a) Lexical Analysis
(b) Syntax Analysis
(c) Semantic Analysis
PART II
(a) Intermediate Code
(b) Code Optimization
(c) Code Generator
Every phase of compilation can interact with a special data structure called "Symbol Table" and with "Error Handler".
PART I
(a) Lexical Analyser: Lexical Analysis reads the source program character by character at a time and units them into a stream of Tokens.
A token is a group of character which represents keywords, operator, and an identifier.
(b) Syntax Analysis:
- During syntax analysis tokens are grouped into grammatical parsed and using some rules.
- The output of Syntax analysis is Parsed Code.
- It is a graphical representation of source code in which operators are placed in the parent node and operands are placed in a leaf node.
example: C = A+B
=
/ \
/ \
C +
/ \
/ \
A B (parsed tree)
(c) Semantic Analysis:
- It is responsible for checking of a semantic error.
- The important concept of Semantic Analysis is type checking.
- The output of a Semantic analysis is Qualified Code.
PART II
(a) Intermediate Code Generator:
- Source code can be represented as three address code because two address are used for storing the value of operand and third address is used for storing the result.
- Code generation is the process by which a compiler converts some intermediate representation of source code into a Machine Code/Object Code.
(b) Code Optimization:
- It improves code quality and efficiency.
- A good optimization technique must have:-
i) Less time and space complexity.
ii) The output of source code should be same after using optimization technique.
iii) A compiler should give less effort for compiling the optimized code.
(c) Code Generation:
- The final phase of the compiler is the generation of Target Code.
Now our next topic is Interpreter, So let's start...
Interpreter?
- It is also a language translator that translates source code into machine code line by line.
- It is slower than the compiler.
- It also belongs to High-level language.
- It detects syntax error at a time of compilation.
- It is easy for the interpreter to detect errors as compared to the compiler.
- When an error occurs, interpreter stops its translation and after removing the error, translation resumes.
- It also provides object code.
Compiler vs Interpreter
(1) A compiler provides several object programs. while An interpreter doesn't generate a permanent saved object code file.
(2) A compiler converts the entire program into machine code at once. while An interpreter translates a program into machine language line by line.
(3) In Compiler remove of Errors (Debugging) is slow. while In interpreter Debugging becomes easier because the errors are pointed out immediately.
(4) A compiler a is complex program hence they require hardcore coding & more memory .while Interpreter is easier to write because they require less memory for program execution.
(5) A compiler is faster as compare to interpreter because whole statements translate once. while Interpreter slower as compare to compiler because they translate each statement line by line.
Thank You 4 reading my blog hope you like it if you like this post then share with your friends :)
if you have any doubts/problems then comment!