You are on page 1of 4

Department of

Computing
Compiler Construction

Class: BSCS
Assignment [01]

Objective:
The objective of this assignment is to provide hands-on experience of System Programming concepts
including:

 Basics of compilers

 Compiler Front End Working

pg. 1
Questions:
i. How many types of compilers available in the market? Discuss them
There are three main types of Compiler which serves as the base for other compilers. Here three
main with some other type of compilers are discussed here:

1. Single Pass Compiler:

Output
Source code Compiler Machine code
Errors

Single Pass Compiler

In single pass Compiler source code directly transforms into machine code. For example, Pascal
language.

2. Two Pass Compiler:

Output
Source code Front End Back End Machine code
Errors

Two Pass Compiler

Two Pass compiler uses an intermediate representation (IR) and admits multiple front ends &
multiple passes.

Two pass Compiler is divided into two sections:

1. Front end: It maps legal code into Intermediate Representation (IR).

 Recognizes legal (& illegal) programs

 Report errors in a useful way

 Produce IR and preliminary storage map

2. Back end: It maps IR onto the target machine.

 Choose machine (assembly) instructions to implement each IR operation

pg. 2
 Ensure conformance with system interfaces

 Decide which values to keep in registers

3. Multi Pass Compilers:

Output
Source code Front End Middle End Back End Machine code
Errors

Multipass Compilers

The multipass compiler processes the source code or syntax tree of a program several times.

 It divided a large program into multiple small programs and process them.

 It develops multiple intermediate codes. All of these multipass take the output of the
previous phase as an input. So, it requires less memory. It is also known as ‘Wide
Compiler’.

Middle End or Intermediate stage is for code improvement or optimization. Like to remove
useless variables, expressions.

 Analyzes IR and rewrites or transforms IR

 Primary goal is to reduce running time of the compiled code. May also improve space
usage, power consumption etc. irrespective of type of algorithm like DP, Greedy etc.

 Must preserve “meaning” of the code.

4. Cross Compilers - They produce an executable machine code for a platform but, this
platform is not the one on which the compiler is running.

5. Bootstrap Compilers - These compilers are written in a programming language that


they have to compile.

pg. 3
6. Source to source/Trans Compiler - These compilers convert the source code of
one programming language to the source code of another programming language.

7. Decompiler - Basically, it is not a compiler. It is just the reverse of the compiler. It


converts the machine code into high-level language.

8. JIT(Just-in-Time) Compiler - The Just-In-Time (JIT) compiler is a component of


the runtime environment that improves the performance of Java applications by
compiling bytecodes to native machine code at run time.

ii. How many ways we are using compilers?


We are using compilers in many different ways. Some of them are:

 Compiler design helps full implementation of High-Level Programming


Languages.
 Support optimization for Computer Architecture Parallelism.
 Design of new memory hierarchies of machines.
 Widely used for Translating Programs. Translates the code from one
language to another.
 Used with other Software Productivity Tools.
 Helps to make the code independent of the platform.
 Makes the code free of syntax and semantic errors. Parses the entire source
code. Checks for any syntax errors in the source code.
 Optionally translates the source code in an intermediate code known as
object code to enhance the performance. Translates the object code to binary
language known as executable code.

pg. 4

You might also like