Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

NAME- MILTON MOLLA

DEPARTMENT- C.S.E
YEAR- 3RD
SEMISTER-5TH
ROLL NO-10600121071
REGISTRATION NO-211060100120005
SUBJECT-COMPILER DESIGN
SUBJECT CODE-PCC-CS501
S
WHAT IS COMPILER
 The compiler is software that converts a program written
in a high-level language (Source Language) to a low-level
language (Object/Target/Machine Language/0’s, 1’s).

 Cross Compiler that runs on a machine ‘A’ and produces a


code for another machine ‘B’. It is capable of creating code
for a platform other than the one on which the compiler is
running.
 Source-to-source Compiler or trans compiler or trans piler
is a compiler that translates source code written in one
programming language into the source code of another
programming language.
FEATURES OF COMPILER
 There are various features of compilers which
are as follows −
 It compiles a large amount of code in less time.
 It needed less amount of memory area to
compile the source language.
 It can compile only the modified code segment if
frequent alterations are needed in the source
code.
 While managing the hardware interrupts best
compilers connect closely with the operating
system.
TYPES OF COMPILER
 There are two types of compilers are
as follows −
 One-Pass Compiler.
 Multi-Pass Compiler.
ONE-PASS COMPILER
 One pass compiler reads the code only
once and then translates it. The one-
pass compiler passes only once
through the parts of each compilation
unit. It translates each part into its
final machine program. In the one-
pass compiler, when the line source is
processed, it is scanned and the token
is extracted.
MULTI –PASS COMPILER

 Compilerscans the input source once


and creates the first modified form,
thus scans the first-produced form.
Such a compiler is known as a multi-
pass compiler.
LANGUAGE PROCESSING
SYSTEM
 We have learnt that any computer system is
made of hardware and software. The hardware
understands a language, which humans cannot
understand. So we write programs in high-level
language, which is easier for us to understand
and remember. These programs are then fed
into a series of tools and OS components to get
the desired code that can be used by the
machine. This is known as Language
Processing System.
LANGUAGE PROCESSING SYSTEM
HIGH LEVEL LANGUAGE

 If a program contains #define or #include


directives such as #include or #define it is
called HLL. They are closer to humans but far
from machines. These (#) tags are called
preprocessor directives. They direct the pre-
processor about what to do.
PRE PROCESSOR
 A preprocessor, generally considered as a
part of compiler, is a tool that produces
input for compilers. It deals with macro-
processing, augmentation, file inclusion,
language extension, etc.
INTERPRETER
 An interpreter, like a compiler, translates high-
level language into low-level machine language.
The difference lies in the way they read the source
code or input. A compiler reads the whole source
code at once, creates tokens, checks semantics,
generates intermediate code, executes the whole
program and may involve many passes. In contrast,
an interpreter reads a statement from the input,
converts it to an intermediate code, executes it,
then takes the next statement in sequence. If an
error occurs, an interpreter stops execution and
reports it. whereas a compiler reads the whole
program even if it encounters several errors.
ASSEMBLER
 An assembler translates assembly
language programs into machine
code.The output of an assembler is
called an object file, which contains a
combination of machine instructions
as well as the data required to place
these instructions in memory.
LINKER

 Linker is a computer program that links and


merges various object files together in order
to make an executable file. All these files
might have been compiled by separate
assemblers. The major task of a linker is to
search and locate referenced
module/routines in a program and to
determine the memory location where these
codes will be loaded, making the program
instruction to have absolute references.
LOADER

 Loader is a part of operating system and is


responsible for loading executable files into
memory and execute them. It calculates the
size of a program (instructions and data) and
creates memory space for it. It initializes
various registers to initiate execution.
CROSS-COMPILER
Acompiler that runs on platform (A)
and is capable of generating
executable code for platform (B) is
called a cross-compiler.
RELOCATABLE MACHINE CODE
 It can be loaded at any point and can
be run. The address within the
program will be in such a way that it
will cooperate with the program
movement.
HOW MANY PHASE OF COPILER
 There are 6 phases in a compiler. Each of this
phase help in converting the high-level langue the
machine code. The phases of a compiler are:
LEXICL ANALYSIS
 Lexical Analysis is the first phase when compiler scans
the source code. This process can be left to right,
character by character, and group these characters into
tokens.
Here, the character stream from the source program is
grouped in meaningful sequences by identifying the
tokens. It makes the entry of the corresponding tickets
into the symbol table and passes that token to next
phase.
The primary functions of this phase are:
 Identify the lexical units in a source code
 Classify lexical units into classes like constants, reserved
words, and enter them in different tables. It will Ignore
comments in the source program
 Identify token which is not a part of the language
LEXICL ANALYSIS
 Example:-
x = y + 10
 Tokens
 X identifier
 = Assignment operator
 Y identifier
 + Addition operator
 10 Number
ADVANTAGES OF COMPILER
 There are various advantages of the compiler
which are as follows −
 A compiler translates a code in a single run.
 It consumes less time.
 CPU utilization is more.
 Both syntactic and semantic errors can be

checked concurrently.
 It is easily supported by many high-level

languages like C, C++, JAVA, etc.


DISADVANTAGE OF COMPILER
 There are various disadvantages of the compiler which
are as follows −
 It is not flexible.
 It consumes more space.
 Error localization is difficult.
 The source program has to be compiled for every
modification.
 It must generate the correct machine code which
should run fast.
 It should be portable.
 It should give diagnostic and error messages.
 It must have consistent optimization
CONCLUSION
 A compiler is an important computer
program used for converting a human-
readable language into a machine
language. It works with other components
such as preprocessors, assemblers, and
loaders to produce an intended output in
the language processing system. It consists
of various phases such as lexical analysis,
syntax analysis, semantic analysis, code
optimization, and code generation.

You might also like