Comprog Lecture 1
Comprog Lecture 1
Computer System
• A set of instructions for a computer to follow is called a
program. The collection of programs used by a computer is
referred to as the software for that computer. The actual
physical machines that make up a computer installation are
referred to as hardware. As we will see, the hardware for a
computer is conceptually very simple.
However, computers now come with a large array of
software to aid in the task of programming. This software
includes editors, translators, and managers of various sorts.
The resulting environment is a complicated and powerful
system
COMPONENTS OF COMPUTER SYSTEM
i) The keyboard
Keyboard (similar to a typewriter) is the main input device of a computer . It contains three types of keys--
alphanumeric keys, special keys and function keys. Alphanumeric keys are used to type all alphabets, numbers and
special symbols like $, %, @, A etc. Special keys such as <Shift>, <Ctrl>, <Alt>, <Home>, <Scroll Lock> etc. are used for
special functions. Function keys such as <Fl>, <F2>, <F3> etc. are used to give special commands depending upon
the software used e.g.F5 reloads a page of an internet browser. The function of each and every key can be well
understood only after working on a PC. When any key is pressed, an electronic signal is produced. This signal is
detected by a keyboard encoder that sends a binary code corresponding to the key pressed to the CPU. There are
many types of keyboards but 101 keys keyboard is the most popular one.
How the keys are organized
The keys on your keyboard can be divided into several groups based on function:
Typing (alphanumeric) keys. These keys include the same letter, number, punctuation, and symbol keys found on a
traditional typewriter.
Special (Control) keys. These keys are used alone or in combination with other keys to perform certain actions. The
most frequently used control keys are CTRL, ALT, the Windows key, and ESC.
Function keys. The function keys are used to perform specific tasks. They are labelled as F1, F2, F3, and so on, up to
F12. The functionality of these keys differs from program to program.
Cursor Movement (Navigation) keys. These keys are used for moving around in documents or WebPages and editing
text. They include the arrow keys, HOME, END, PAGE UP, PAGE DOWN, DELETE, and INSERT and ARROW KEYS.
Numeric keypad. The numeric keypad is handy for entering numbers quickly. The keys are grouped together in a
block like a conventional calculator or adding machine.
B. POINTING DEVICES
Are devices that enter data and instructions into the computer using a pointer that appears on
the screen. The items to be entered are selected by either pointing to or clicking on them. e.g
mice, joystick, touch sensitive screen, trackballs
i) THE MOUSE
A mouse is a small device used to point to and select items on your computer screen. Although
mice come in many shapes, the typical mouse does look a bit like an actual mouse. It's small,
oblong, and connected to the system unit by a long wire that resembles a tail and the connector
which can either be PS/2 or USB. Some newer mice are wireless.
A mouse usually has two buttons: a primary button (usually the left button) and a secondary
button. Many mice also have a wheel between the two buttons, which allows you to scroll
smoothly through screens of information.
When you move the mouse with your hand, a pointer on your screen moves in the same
direction. (The pointer's appearance might change depending on where it's positioned on your
screen.) When you want to select an item, you point to the item and then click (press and release)
the primary button. Pointing and clicking with your mouse is the main way to interact with your
computer. There are several types of mice: Mechanical mouse, optical mouse, optical-mechanical
mouse and laser mouse.
Basic parts
A mouse typically has two buttons: a primary button (usually the left button) and a secondary
button (usually the right button). The primary button is the one you will use most often. Most
mice also include a scroll wheel between the buttons to help you scroll through documents and
WebPages more easily. On some mice, the scroll wheel can be pressed to act as a third button.
Pointing to an object often reveals a descriptive message about it.The pointer can change depending
on what you're pointing at. For example, when you point to a link in your web browser, the pointer
changes from an arrow to a hand with a pointing finger .
Most mouse actions combine pointing with pressing one of the mouse buttons. There are four basic
ways to use your mouse buttons: clicking, double-clicking, right-clicking, and dragging.
Clicking (single-clicking)
To click an item, point to the item on the screen, and then press and release the primary button
(usually the left button).
Clicking is most often used to select (mark) an item or open a menu. This is sometimes called single-
clicking or left-clicking.
Double-clicking
To double-click an item, point to the item on the screen, and then click twice quickly. If the two clicks
are spaced too far apart, they might be interpreted as two individual clicks rather than as one
double-click.
Double-clicking is most often used to open items on your desktop. For example, you can start a
program or open a folder by double-clicking its icon on the desktop.
Right-clicking
To right-click an item, point to the item on the screen, and then press and release the secondary
button (usually the right button).
Right-clicking an item usually displays a list of things you can do with the item. For example, when
you right-click the Recycle Bin on your desktop, Windows displays a menu allowing you to open it,
empty it, delete it, or see its properties. If you are unsure of what to do with something, right-click it.
• C) SCANNING DEVICES
Are devices that capture an object or a document directly from the
source. They are classified according to the technology used to capture
data e.g. Scanners and Document readers.
i) Scanners
Used to capture a source document and converts it into an
electronic form.
Example are - Flatbed and Handheld scanners.
• This is the part that holds all of the parts of a computer to make up the computer system.
• It is usually designed in such a manner to make fitting a motherboard, wiring, and drives as easy
as possible. Some are designed so well that it is easy to make everything look tidy and
presentable too.
• Cases come in all different sizes and shapes to accommodate various types of computer
components and satisfy the consumer’s needs.
• Design elements can vary from being plain to highly elaborate. You can get a plain grey desktop
case or one with colored lighting everywhere to make it look spectacular.
• Computer cases rely on computer fans inside them to create proper airflow to keep all the
internal parts cool and working reliably.
• A computer case, like most things, varies in quality. You can get them made from cheap metals or
• Motherboard
The motherboard is the main board that is screwed directly inside the computer case. All
other cards and everything else plugs directly into the motherboard, hence its name.
The CPU, RAM, drives, power supply, and more are connected to it.
Its function involves integrating all the physical components to communicate and operate
together.
A good motherboard offers a wide amount of connectivity options. It also has the least
amount of bottlenecks possible.
This allows all the components to operate efficiently and to fulfill their maximum potential
as they were designed to do.
Obviously, as the physical size is reduced, it begins to limit connectivity options and
functionality.
• Central Processing Unit (CPU)
This little chip is known as the central processing unit (CPU), and it is the brain of
the computer where all data crunching and processing is done. In the old days, a
CPU used to have “only one single brain” or what we call a “single-core CPU”.
But as the wise saying goes “two heads are better than one”, so smart monkeys
eventually improved the design of CPUs. Even though it is one physical chip, there
could multiple “brains” (or cores) within that chip. This is where the terms dual-
core (2 processors in one chip), quad-core (4 processors), and multi-core (N
processors) come from.
• Storage Unit
- Storage unit is main part of our computer system.
- Our computer is incomplete without a storage unit because without a
storage unit, we will not be able to store any type of data like documents
files, audio files, video files etc. in our computer.
Because of the storage unit, we are able to store any type of data so that we
can use that data when we need it in the future.
Because the storage unit we have stored our data, it is saved until we delete
that data, then that data is saved in the storage unit.
- In simple words, your operating system is also installed in the storage
unit itself.
Earlier storage units were not capable of storing much data but today's
storage units are capable of storing a very large amount of data.
-ROM
• RAM
RAM stands for Random Access Memory. It is temporary and volatile memory.
Temporary means - RAM memory does not store any data permanently as it stores any data
as long as that data is being worked on at the present time, as soon as the purpose of that
data is served, Then Ram considers it as useless data and deletes that data.
As soon as you turn on your computer, your operating system is loaded in the RAM memory
itself and when the operating system is fully loaded then your computer is on.
These memory are capable of transferring data much faster than HDD and SSD.
RAM memory is installed in the slot of the motherboard.
• ROM
ROM stands for Read Only Memory. It is permanent and non volatile memory.
This memory can also not be used by the user, this memory is used for the use of the
computer system.
The instruction data is already programmed in the ROM, which instruction is to be executed
when.
ROM does not have the capacity to store large amounts of data.
No user can delete the data of ROM.
• Graphics Card
-A graphics card is an output device that processes the data from the motherboard and sends the
appropriate information to the computer’s screen for display.
-You can connect monitors to it using HDMI, DisplayPort, DVI, or VGA connectors.
-It can also be referred to as a video or display card.
-A video card takes the burden of all the video processing from the main CPU. This gives a computer
a big boost in performance.
-Because of the large processing requirements for a gaming GPU, fans are almost a given.
-A video card plugs into a PCI Express (Peripheral Component Interconnect Express) slot on the
motherboard. It is a serial expansion bus slot capable of high bandwidth in two directions.
-A graphics card has a GPU (Graphics Processing Unit), the main part of a computer system that
requires cooling.
-A graphics processing unit is slower than a CPU but is designed to deal with mathematical operations
required for video rendering.
- The card’s memory amount varies depending on the manufacturer’s design.
-Video cards use GDDR (Graphics Double Data Rate) SDRAM, which is specially designed to optimize
graphics performance.
- GDDR is built to handle a higher bandwidth compared to plain DDR ram.
• Sound Card
-Most of the time, the sound chip built into the motherboard is used for audio
output.
-But, if you are a sound enthusiast or prefer high-quality audio output while
playing a game, you might be inclined to use a sound card.
-External DACs have gained much more popularity and help deliver clearer and
more defined audio or high-definition sound output.
-They connect up using an IO cable like a USB cable to your computer or laptop
and provide a line out for your speakers or headphones.
-A sound processing chip on the card does all of the audio processing and is
usually not a very powerful processor.
• UPS
-UPS stands for uninterruptible power supply. UPS just like a battery.
-This is also a main part of the computer, without which our computer is incomplete.
After the power cut, the uninterruptible power supply provides electricity to our computer so that our computer
continues to run even after the power cut.
With UPS, you cannot run the computer for a long time, UPS can capable for run the computer for a few hours.
UPS keeps the computer safe and also keeps the user's work safe.
For example, if you are working continuously for a few hours on a MS Word document file and suddenly the electricity is
cut off, then your computer will be turned off and all that you were working on the document file will also be deleted.
If you use UPS, your computer system will not shut down even after the line is cut and the document file you were
working on will not be deleted.
If the line is cut frequently and you do not use the UPS, then your computer system may also crash.
Laptops and notebooks have batteries, in these computers, the battery acts as a UPS.
The battery of laptop and notebook is very powerful, even after the line is cut, you can use laptop and notebook for
about 6 to 8 hours.
• Power Supply Unit
- A power supply is the main part of a computer because without a power supply
our computer is not open.
- Power Supply Unit means - Power supply An electronic component that provides
electrical energy to a computer system that runs the computer.
- This power supply to the computer system as much power as the computer
needs.
- It controls the electrical voltage of your computer and helps your computer
system to run properly without overheating.
- This power supply unit is in every computer.
- The power supply looks like a metal box with a small fan inside.
• Power Cord
- The power cord is also the part of a computer system
that supplies electricity to run the computer system.
Power cord This is a type of cable.
- This cable is connected to the UPS on one side and to
the computer case from the other side. There are many
other types of cables in computer systems that work to
connect monitors, printers, scanners, webcams, etc. to
the CPU.
• CD/DVD Drive
- CD and DVD drives are also optional parts of computer systems.
CD stands for (Compact Disc) and DVD stands for (Digital Versatile
Disc).
- CD and DVD drives are used to read and write images, videos,
software, and other types of data. - CD and DVD discs are a type
of optical disc.
- CD and DVD drives read and write data from optical discs
through laser technology.
- This drive is still used to install operating systems, watch movies,
or do other things. CD and DVD drives are found in almost all
types of computer systems.
• FANS & HEATSINKS
- A fan is an important and internal part of a computer system whose main
function is to cool the components of a computer system by circulating air.
- If your computer system does not have a fan, then your computer system can
fail quickly.
- Because if you use the computer system for a long time, then the components
of your computer become hot, due to which those components get spoiled.
- That's why every computer system has a fan so that when the computer's
components get hot when the computer is used for a long time, the fan works
to cool those hot components.
- So that your computer system lasts for a long time and does not get damaged.
- Through the computer bios, the speed of the computer fan is controlled based
on the temperature of the component concerned.
- Fans are used to cool the components, to prevent a meltdown from occurring.
• There are different types of fans, which names are given below.
- Case Fan
- CPU Fan
- GPU Fan
- Power supply Fan.
A network consists of a number of computers connected, so they may share
resources, such as printers, and may share information. A network might contain a
number of workstations and one or more mainframes, as well as shared devices such
as printers.
For our purposes in learning programming, it will not matter whether you are
working on a PC, a mainframe, or a workstation. The basic configuration of the computer,
as we will view it, is the same for all three types of computers.
The computer can be thought of as having five main components: the input
device(s), the output device(s), the processor (also called the CPU), the main memory,
and the secondary memory. The processor, main memory, and sometimes even
secondary memory are normally housed in a single cabinet. The processor and main
memory form the heart of a computer and can be thought of as an integrated unit.
Other components connect to the main memory and operate under the direction of
the processor.
An input device is any device that allows a person to communicate information
to the computer. Your primary input devices are likely to be a keyboard and a mouse.
An output device is anything that allows the computer to communicate information
to you. The most common output device is a display screen, referred to as a monitor.
Quite often, there is more than one output device. For example, in addition to the
monitor, your computer probably has a printer for producing output on paper. The
keyboard and monitor are sometimes thought of as a single unit called a terminal.
In order to store input and to have the equivalent of scratch paper for performing
calculations, computers are provided with memory. The program that the computer
executes is also stored in this memory. A computer has two forms of memory, called
main memory and secondary memory. The program that is being executed is kept in
main memory, and main memory is, as the name implies, the most important memory.
Main memory consists of a long list of numbered locations called memory
locations; the number of memory locations varies from one computer to another,
ranging from a few thousand to many millions, and sometimes even into the billions.
Each memory location contains a string of zeros and ones. The contents of these
locations can change. Hence, you can think of each memory location as a tiny blackboard
on which the computer may write and erase. In most computers, all memory
locations contain the same number of zero/one digits.
A digit that can assume only the values zero or one is called a binary digit or a bit. The
memory locations in most computers contain eight bits (or some multiple of eight bits).
An eight-bit portion of memory is called a byte, so we may refer to these numbered
memory locations
as bytes. To rephrase the situation, you can think of the computer’s main
memory as a long list of numbered memory locations called bytes. The number that
identifies a byte is called its address. A data item, such as a number or a letter, can
be stored in one of these bytes, and the address of the byte is then used to find the
data item when it is needed.
If the computer needs to deal with a data item (such as a large number) that is
too large to fit in a single byte, it will use several adjacent bytes to hold the data item.
In this case the entire chunk of memory that holds the data item is still called a
memory location. The address of the first of the bytes that make up this memory
location is used as the address for this larger memory location. Thus, as a practical
matter, you can think of the computer’s main memory as a long list of memory locations
of varying sizes. The size of each of these locations is expressed in bytes and
the address of the first byte is used as the address (name) of that memory location.
The sizes of
the memory locations are not fixed, but can change when a new program is run on
the computer.
The fact that the information in a computer's memory is
represented as zeros and ones need not be of great
concern to you when programming in C++ (or in most any
other programming language). There is, however, one
point about this use of zeros and ones that will concern us
as soon as we start to write programs. The computer
needs to interpret these strings of zeros and ones as
numbers, letters, instructions, or other types of
information. The computer performs these interpretations
automatically according to certain coding schemes. A
different code is used for each different
type of item that is stored in the computer’s memory: one
code for letters, another for whole numbers, another for
fractions, another for instructions, and so on.
For example, in one commonly used set of codes, 01000001 is the
code for the letter A and also for the number 65. In order to know
what the string 01000001 in a particular location stands for, the
computer must keep track of which code is currently being used for
that location. Fortunately, the programmer seldom needs to be
concerned with such codes and can safely reason as though the
locations actually contained letters, numbers, or whatever is desired.
The memory we have been discussing up until now is the main
memory. Without its main memory, a computer can do nothing.
However, main memory is only used while the computer is actually
following the instructions in a program. The computer also has
another form of memory called secondary memory or secondary
storage. (The words memory and storage are exact synonyms in this
context.)
Secondary memory is the memory that is used for keeping a
permanent record of information after (and before) the computer is
used. Some alternative terms that are commonly used to refer to
secondary memory are auxiliary memory, auxiliary storage,
external memory, and external storage.
Information in secondary storage is kept in units called files, which can be as
large or as small as you like. A program, for example, is stored in a file in secondary
storage and copied into main memory when the program is run. You can store a program,
a letter, an inventory list, or any other unit of information in a file.
Several different kinds of secondary memory may be attached to a single computer.
The most common forms of secondary memory are hard disks, diskettes, and
CDs. (Diskettes are also sometimes referred to as floppy disks.) CDs (compact disks)
used on computers are basically the same as those used to record and play music.
CDs for computers may be read-only so that your computer can read, but cannot
change, the data on the CD; CDs for computers can also be read/write CDs, which
can have their data changed by the computer. Information is stored on hard disks and
diskettes in basically the same way as it is stored on CDs. Hard disks are fixed in
place and are normally not removed from the disk drive. Diskettes and CDs can be
easily removed from the disk drive and carried to another computer. Diskettes and
CDs have the advantages of being inexpensive and portable, but hard disks hold
more data and operate faster. Other forms of secondary memory are also available,
but this list covers most forms that you are likely to encounter.
Main memory is often referred to as RAM or random access memory. It is
called random access because the computer can immediately access the data in any
memory location. Secondary memory often requires sequential access, which
means that the computer must look through all (or at least very many) memory
locations until it finds the item it needs.
The processor (also know as the central processing unit, or CPU) is the
“brain” of the computer. When a computer is advertised, the computer company will
tell you what chip it contains. The chip is the processor. The processor follows the
instructions in a program and performs the calculations specified by the program. The
processor is, however, a very simple brain. All it can do is follow a set of simple
instructions provided by the programmer. Typical processor instructions say things
like “Interpret the zeros and ones as numbers, and then add the number in memory
location 37 to the number in memory location 59, and put the answer in location 43,”
or “Read a letter of input, convert it to its code as a string of zeros and ones, and place
it in memory location 1298.” The processor can add, subtract, multiply, and divide
and can move things from one memory location to another. It can interpret strings of
zeros and ones as letters and send the letters to an output device. The processor also
has some primitive ability to rearrange the order of instructions. processor instructions
vary somewhat from one computer to another. The processor of a modern computer
can have as many as several hundred available instructions. However, these instructions
are typically all about as simple as those we have just described.
Software
You do not normally talk directly to the computer, but communicate with it through
an operating system. The operating system allocates the computer’s resources to
the different tasks that the computer must accomplish. The operating system is
actually a program, but it is perhaps better to think of it as your chief servant. It is in
charge of all your other servant programs, and it delivers your requests to them. If
you want to run a program, you tell the operating system the name of the file that
contains it, and the operating system runs the program. If you want to edit a file, you
tell the operating system the name of the file and it starts up the editor to work on
that file. To most users the operating system is the computer. Most users never see
the computer without its operating system. The names of some common operating
systems are UNIX, DOS, Linux, Windows, Macintosh, and VMS.
A program is a set of instructions for a computer to follow. The input to a computer can be
thought of as consisting of two parts, a program and some data. The computer follows the
instructions in the program, and in that way, performs some process. The data is what we
conceptualize as the input to
the program. For example, if the program adds two numbers, then the two numbers
RAM processor, chip operating system program data are the data.
Types of computer software
Three types of computer programs are: application
Software, system software and utility.
• Application software consists of those programs
written to perform particular tasks required by the users.
• System software is the collection of programs
that must be available to any computer system for it to
operate.
Operating systems like Windows, macOS, Android and iOS
are examples of system software. Operating systems are
loaded into RAM when the device starts up, and have
access to the hard drive.
• Utility software
- Utility software is part of the system software and
performs specific tasks to keep the computer running.
Utility software is always running in the background.
Examples of utility software are security and optimisation
programs.
- Security programs include anti-virus software that scans
and removes viruses. Most computers will include some
sort of anti-virus software, but you can add your own.
- Optimisation programs can include tools for system
clean-up, disk defragmentation, and file compression.
These tools are typically installed as part of the operating
system. They have access to the hard drive to keep it tidy.
The operating system
• Application software also uses the operating system
to talk to the hardware on the computer and to
other software. When a web browser wants to load a
web page, it is the operating system that controls
access to the internet and fetches the information
from the web.
• Similarly, the operating system also provides the
application software information about what key is
being pressed, and about the mouse: where it is,
what it clicked, and where it’s moving on screen.
• Application software relies heavily on the operating
system to do these tasks and send it all this
In other words, the data is the input to the program,
and both the program
and the data are input to the computer (usually via
the operating system).
Whenever we give a computer both a program to
follow and some data for the program,
we are said to be running the program on the data,
and the computer is said to execute the program on
the data. The word data also has a much more
general meaning than the one we have just given it.
In its most general sense it means any information
available to the computer. The word is commonly
used in both the narrow sense and the more general
sense.
High-Level Languages
• A computer program is just a collection of the
instructions necessary to solve a specific problem.
The basic operations of a computer system from
what is known as the computer’s instruction set.
And the approach or method that is used to solve
the problem is known as an algorithm.
• So far as programming language concern these are
of two types.
1) Low level language
2) High level language
Low level language:
• Low level languages are machine level and assembly level
language. In machine level language computer only
understand digital numbers i.e. in the form of 0 and 1. So,
instruction given to the computer is in the form binary digit,
which is difficult to implement instruction in binary code. This
type of program is not portable, difficult to maintain and also
error prone. The assembly language is on other hand modified
version of machine level language. Where instructions are
given in English like word as ADD, SUM, MOV etc. It is easy to
write and understand but not understand by the machine. So
the translator used here is assembler to translate into machine
level. Although language is bit easier, programmer has to know
low level details related to low level language. In the assembly
level language the data are stored in the computer register,
which varies for different computer. Hence it is not portable.
• Machine languages are the lowest level of
computer languages. Programs written in
machine language consist of 1s and 0s.
• Programs in machine language can control
directly to the computer’s hardware.
• Example:
00101010 000000000001 000000000010
10011001 000000000010 000000000011
COMPILER INTERPRETER
A Compiler is used to compile An interpreter is used to
an entire program and an translate each line of the
executable program is program code immediately as
generated through the object it is entered
program
The executable program is The executable program is
stored in a disk for future use generated in RAM and the
or to run it in another interpreter is required for each
computer run of the program
The compiled programs run The Interpreted programs run
faster slower
Most of the Languages use A very few languages use
compiler interpreters.
• Differences Between Compiler and Assembler
Compiler Assembler
Compiler converts the high-level An assembler converts the assembly
language source code into machine level language code into the
level language code. machine level language code.
The input of a compiler is high-level Where as, its input is low level
language source code. assembly code.
Compiler converts the whole source Assembler does not convert the
code to machine code at once. code in one go.
It has the following phases: lexical An assembler completes the task in
analysis, syntax analysis, semantic two passes.
analysis, intermediate code
generation, code optimization, code
generation and error handling.
It produces a machine code in form It produces binary code in form of 0s
of mnemonics. and 1s.
Examples are Java, C, C++ etc. Examples of assemblers are GAS,
compilers. GNU etc.
• Integrated Development Environments (IDE) The
process of editing, compiling, running, and debugging
programs is often managed by a single integrated
application known as an Integrated Development
Environment, or IDE for short. An IDE is a windows-
based program that allows us to easily manage large
software programs, edit files in windows, and compile,
link, run, and debug programs. On Mac OS X,
CodeWarrior and Xcode are two IDEs that are used by
many programmers. Under Windows, Microsoft Visual
Studio is a good example of a popular IDE. Kylix is a
popular IDE for developing applications under Linux.
Most IDEs also support program development in
several different programming languages in addition to
Compilers
• A program that translates a high-level language like C++ to a machine language is
called a compiler. A compiler is thus a somewhat peculiar sort of program, in that its
input or data is some other program, and its output is yet another program. To avoid
confusion, the input program is usually called the source program or source code,
and the translated version produced by the compiler is called the object program or
object code. The word code is frequently used to mean a program or a part of a
program, and this usage is particularly common when referring to object programs.
Now, suppose you want to run a C++ program that you have written. In order to get the
computer to follow your C++ instructions, proceed as follows. First, run the compiler
using your C++ program as data. Notice that in this case, your C++ program is not
being treated as a set of instructions. To the compiler, your C++ program is just a long
string of characters. The output will be another long string of characters, which is the
machine-language equivalent of your C++ program. Next, run this machine-language
program on what we normally think of as the data for the C++ program. The output
will be what we normally conceptualize as the output of the C++ program.
• Linking
• The object code for your C++ program must be
combined with the object code for routines (such
as input and output routines) that your program
uses. This process of combining object code is
called linking and is done by a program called a
linker. For simple programs, linking may be done
for you automatically.
• Compiler
• The compiler is a system program that converts the source code into the machine
language. The machine language is also called as an object code, which is generated as
an output of the compilation process. The compiler generates an ‘.obj’ file on the disk
after the successful compilation of the source code as shown in Figure 1.13. There are
three major tasks, which are performed on the source code as a part of compilation
process. These are the key phases of the compilation process and they are as explained
below:
1) Syntax analysis: Program can be translated into the machine code only if the
source code written by the programmer does not violate any of the syntactical rules
defined by the language. The syntax phase is used to check if the syntax of the source
code is correct. The component inside compiler that validates the syntax of the program
is called as a parser. The parser will throw an ‘error’ message to the programmer if any
of the syntax rules are violated. The translation process is immediately terminated if
at least one error is located in the input program. Every programming language has a
grammar, which defines the syntactical rules of that language. A parser is a
program that checks if the input sentence preservers the syntactical rules, which are
defined by the grammar of the language, thereby detecting syntax errors (if any) in the
source code. So as to examine the sentence for syntax errors, the compiler partitions the
sentence into discrete tokens. The process of partitioning a single sentence into
separate tokens is called as ‘lexical analysis’, which happens before the ‘syntax analysis’
phase of the compilation process.
2) Semantic analysis: The phase is used to check
the input program for the semantic errors. The
semantic rules define the ‘data types’ over which a
specific operation can be performed. The semantic
phase will throw an error and stop the translation
process if there is a ‘data type’ mismatch while
performing an operation.
3. Code generation: Once the syntax and semantic
analyses are completed successfully, the code
generation phase generates the optimized object
code (which is the machine language) on the disk.
The object code for the program is created and
stored as an ‘.obj’ file on the disk.
SOFTWARE DEVELOPMENT METHOD