Uploaded by a.salam

Chapter 1(XII)

advertisement
Chapter 1
Concept Of Computer Programming
Problem Solving Process:The Problem solving is a process of transforming the description of a problem into the solution of that
problem by using our knowledge of the problem domain and by relying on our ability to select and use
appropriate problem solving strategies, techniques and tools. The Problem solving is the act of defining a
problem; determining the cause of the problem; identifying, prioritizing, and selecting alternatives for a
solution; and implementing a solution. The Problem solving (within the context of developing programs)
refers to analyze a problem with the intention of deriving a solution for the problem. The process of
programming which is also called software engineering involves the following steps.
*
*
*
*
*
Defining the Problem
Planning the Solution
Coding the Program
Testing the Program
Documenting the Program
1. Defining
Problem
5. Documenting
the Program
4. Testing
the Program
2. Planning
Solution
3. Coding
the Program
1.
Defining the problem
It is impossible to develop a solution to a problem if you do not have a clear understanding of
the problem itself. The very first task for a programmer is to have a clear understanding the
problem, that what the problem is and how it will be solved. The following steps are
considered important. Defining the problem requires that the program specify four mini tasks.
They are:
a) Determining Program Objectives
Every day user determines the objective of the problem they are trying to solve.
Program works in the same way, the programmer defines what are the major tasks
and the main purpose of the program. The programmer defines a clear boundary
about the goals of the program.
b) Determining the Desired Out Put
It is always better to understand the output of a program before you specify the input.
It needs to be defined that what type of reports are required in the form of Hard Copy
or Soft Copy.
c) Determining the Input Data
Once you know the output, you want; you can determine the input data requirement.
What kind of input data is needed? What form should it appear in? What is its source?
What type of style of user interface is required by the user? The input requirements are
identified by the programmer so that the desired output can be obtained.
d) Determining the Processing Requirements
Here you make sure you understand the operations which must be performed in order to
process the data. The requirements for the hardware and software need to be defined
the problem definition. So this task is also included in the first step.
2.
Planning the Solution
After defining the problem, the programmer is supposed to plan for the solution using some
design tools. These techniques include the following:a) Top – Down Program Design A top-down design is the decomposition of a system
into smaller parts in order to comprehend its compositional sub-systems.
In top-down design, a system's overview is designed, specifying, yet not detailing any
first-level subsystems. Then, every subsystem is refined in greater detail, for
example, sometimes dividing into many different levels of subsystem, so that the
whole specification is decomposed to basic elements.
As soon as these base elements are identified, it is easier to build these elements as
computer modules. Once the modules are built, it is effortless to put them together,
building the whole system from these individual elements.
A top-down design is also known as a stepwise design.
b) Algorithm
An algorithm is a step by step method of solving a problem. It is commonly used for
data processing, calculation and other related computer and mathematical operations.
An algorithm is also used to manipulate data in various ways, such as inserting a new
data item, searching for a particular item or sorting an item.
c) Flow chart
The flow chart is a pictorial representation of the program logic which makes easy to
understand the program. A flow chart representing a process using different symbols
containing information about steps or a sequence of events. Each of these symbols is
linked with arrows to illustrate the flow direction of the process.
3.
Coding the Program
Once an algorithm has been developed and its flowchart has been completed, the next step
is to code the program. Coding is the process of writing instructions in a programming
language. The language used depends on the system resources available, the expertise of
the programmer and the type of application.
4.
Testing the Program
Once the program has been coded completely the next phase is the implementation. The
testing phase makes sure that the program fulfills all the objectives which are required for the
user.
Programming error are known as bugs and the process of detecting and correcting these
errors is called debugging.
By the implementation the programmer comes to know the physical and logical errors which
are supposed to be debug. The program is tested regarding all types of errors that are
syntax errors, logical errors and run time errors.
The Debugging Process
The process through which a program can be made error free and properly functional is
called debugging process. Several tools have been developed for finding and removing three
types of errors, as follows:
Desk Checking
In the desk checking, a programmer checks a printout of the program while sitting at a desk.
The programmer goes through the listing line by line looking for syntax, logic and runtime
errors. In other words, desk checking is a sort of proof-reading.
Manual Testing With Sample Data
Both correct and incorrect data are run through the program manually, not with a computer –
to – test for correct processing results. This is called dry run of program. If any error is found
then it is removed before further testing.
Structured Walkthrough
A structured walk through is a process in which three or four programmers, including the
creator of the program, review (walk through) the program. They analyze it for completeness,
accuracy, and quality of design and then discuss their conclusions.
Attempt at Translation
The program is run through a computer, using a translator program. The translator attempts
to translate the written program from the programming language (such as C or PASCAL) into
the machine language of 1s and 0s. Before the program will run, it must be free of syntax
errors. These syntax errors will be identified by the translating program.
Testing Sample Data on the Computer
When all syntax errors have been corrected in the program statements, we must plan the
sample data carefully to make sure you test every part of the program. This step is
sometimes called alpha testing.
Run Real – World Data
After testing with sample data, the program may run fine – in the laboratory. However, if the
program is going to be sold commercially, it is released to a selected set of users to be
tested with real data, called beta testing. The selected users locate errors that were
overlooked during the regular testing phase and report them to the company that is
developing the program. After beta testing, the program may need additional debugging
before it is released to stores.
5.
Documenting the Program
Documentation is an essential phase of the programming process. It is not a separate
phase. It is continued with all the steps in programming from problem definition to testing.
Error and its types
The
programmer
should
know
the
fact
that
there
is
very
less
chances that a program will run perfectly in first time. It doesn’t matter how
nicely the designing is done and how much care is taken while coding. One can’t
say that the program would 100% error free. So the programmer has to make
efforts to detect and rectify any kind of errors that are present in the
program. Program errors are also referred as program bugs and the process of detecting
and correcting these errors is called debugging. By the implementation the programmer
comes to know the physical and logical errors which are supposed to be debug. The
program is tested regarding all types of errors that are:
 Syntax errors
 Logical errors
 Run time errors.
Syntax errors
Syntax errors represent grammar errors in the use of the programming language. Common examples are:
 Misspelled variable and function names
 Missing semicolons
 Unmatched parentheses, square brackets, and curly braces
 Using a variable that has not been declared
 Incorrect format in selection and loop statements
Syntax errors are the easiest to find and fix. Over the years, compiler developers have worked hard to
make compilers smarter so that they can catch errors at compile time that might otherwise turn out to be
runtime errors.
Logic errors
Logic errors occur when a programmer implements the algorithm for solving a problem
incorrectly. A statement with logical error may produce unexpected and wrong results in the
program. Common examples are:
 Multiplying when you should be dividing
 Adding when you should be subtracting
 Opening and using data from the wrong file
 Displaying the wrong message
Logic errors are the hardest to find and fix because:
 The compiler does not detect these errors
 There is no indication of error when the program is executed.
 The program may produce correct results for some input data and wrong results for other
input data.
Logic errors can only be detected by examining the program thoroughly. This is usually done by
using a debugger.
Runtime errors
A type of error that occurs during the execution of a program is known as run-time error.
Runtime errors may crash your program when you run it. Runtime errors occur when a program
with no syntax errors directs the computer to execute an illegal operation. Common examples
are:

Trying to divide by a variable that contains a value of zero
Trying to open a file that does not exist
There is no way for the compiler to know about these kinds of errors when the program is
compiled. Errors are commonly due to wrong input from the user. Runtime errors are usually
more difficult to find and fix than syntax errors.
To find the source of a run-time error in a program, usually a software called debugger is used.

Computer/Programming Languages
Computer Program:- A program is a set of instructions following the rules of the chosen language.
Without programs, computers are useless. A program is like a recipe. It contains a list of ingredients
(called variables) and a list of directions (called statements) that tell the computer what to do with
the variables. A program is a set of instructions written in a language (such as C) understandable
by the computer to perform a particular function on the computer. A well written program could be
parceled well to form an application package customized for solving a specific type of problem on
the computer system. A computer programmer is a computer scientist (a professional) skilled in
using constructs of programming languages to develop executable and acceptable computer
programs. A software developer is a programmer who often works hand in hand with system
analysts on large projects.
Software:-Software is a collection of integrated programs having a definite purpose. The software
is a computer program which is built using some computer language. It is a collection of programs
which works integratedly. The software that controls and manages the hardware is called system
software and the software which facilitates the user is called application software.
Example
MS – Word
Typing Master
MS – Excel
Operating System
etc.
Programming Language • A programming language is a vocabulary and set of grammatical rules
(syntax) for instructing a computer to perform a specific task .Programming languages can be used
to create computer programs. • The term programming language usually refers to high-level
languages, such as BASIC, C, C++, COBOL, FORTRAN, Ada, and Pascal.
A computer language is defined as the source of communication to the computer system which
provides all the materials to develop programs and consequently complete software. Languages
that programmers use to write code are called "high-level languages." This code can be compiled
into a "low-level language," which is recognized directly by the computer hardware.
The portion of the language that a computer can understand is called a “binary.” Translating
programming language into binary is known as “compiling.” Each language, from C Language to
Python, has its own distinct features, though many times there are commonalities between
programming languages.
Programming languages are artificial notational languages created or developed to be used in
preparing coded instructions on the computer for later execution by the computer. They are usually
composed of series of usage rules (syntax) that determine the meaning (semantics) of expressions
written in the language. Each programming language comes handy with its own translator i.e
interpreter or compiler. These languages allow computers to quickly and efficiently process large
and complex swaths of information. For example, if a person is given a list of randomized numbers
ranging from one to ten thousand and is asked to place them in ascending order, chances are that
it will take a sizable amount of time and include some errors.
Programming is the art of developing computer programs with the aid of selected programming
language by a computer programmer. It is a special skill whose quality is tested by the quality of the
resulting program or software. In programming, programming stages must be properly followed, i.e
from problem definition to maintenance and review. There are dozens of programming languages
used in the industry today.
Characters of Programming Languages
Although there are many different programming languages, each one designed to solve certain
types of problems; all of them have the basic functions of directing the operations of a computer.
Therefore, certain general classes of instructions are present in every programming language,
which can be categorized as follows:
Input/output Instructions: These instructions direct the computer to “read from” or “write to” a peripheral device
(for example, disk drive or a printer).
Computation Instructions: These instructions direct the computer to perform arithmetic operations (add,
subtract, multiply, divide, and raise a number to a power).For example, PAY= HOURS X RATE computes gross
earnings for hourly employees.
Control Instructions: These instructions can alter the sequence of the program’s execution or terminate
execution. For example, in an accounts receivable program, different sequences of instructions are executed for
customers who pay on time and for those who pay after the due date.
Assignment Instructions: These instructions transfer data internally from one RAM location to another .For
example, a data item may be copied from one location to another, the result of a computation may be stored at a
specified location, or an intermediate result may retrieve from a given location.
Types of Computer/Programming Languages
Introduction:
A language is the main medium of communicating between the Computer systems and the most common are the
programming languages. As we know a Computer only understands binary numbers that is 0 and 1 to perform
various operations, but the languages are developed for different types of work on a Computer. A language
consists of all the instructions to make a request to the system for processing a task. From the first generation
and now the fifth generation of the Computers there were several programming languages used to communicate
with the Computer. Here we will go into the detail of the Computer language and its types.
Computer Language Description:
A Computer language includes various languages that are used to communicate with a Computer machine. Some
of the languages like programming language which is a set of codes or instructions used for communicating the
machine. The machine code is also considered as a computer language that can be used for programming. And
also HTML which is a computer language or a markup language, but not a programming language. Similarly,
there are different types of languages developed for different types of work to be performed by communicating
with the machine.
There are three types of programming languages Low-level language , High level language and Middle Level
Languages.
Low Level Language:
Low level language is one which is close to machine (computer).It is easier for machines to understand and
difficult for humans to understand. It is faster in execution as compared to high level and middle level languages.
Low level languages are the machine codes in which the instructions are given in machine language in the form of
0 and 1 to a Computer system. It is mainly designed to operate and handle all the hardware and instructions set
architecture of a Computer. The main function of the Low level language is to operate, manage and manipulate
the hardware and system components. There are various programs and applications written in low level
languages that are directly executable without any interpretation or translation. Low level language is divided into
two parts are Machine language and Assembly language.


Machine Language is one of the low-level programming languages which is the first generation language
developed for communicating with a Computer. It is written in machine code which represents 0 and 1
binary digits inside the Computer string which makes it easy to understand and perform the operations. As
we know a Computer system can recognize electric signals so here 0 stands for turning off electric pulse
and 1 stands for turning on electric pulse. It is very easy to understand by the Computer and also increases
the processing speed.
The main advantage of using Machine language is that there is no need of a translator or interpreter to
translate the code, as the Computer directly can understand. But there are some disadvantages also like
you have to remember the operation codes, memory address every time you write a program and also hard
to find errors in a written program. It is a machine dependent and can be used by a single type of
Computer.
Assembly Language is the second generation programming language that has almost similar structure
and set of commands as Machine language. Instead of using numbers like in Machine languages here we
use words or names in English forms and also symbols. The programs that have been written using words,
names and symbols in assembly language are converted to machine language using an Assembler.
Because a Computer only understands machine code languages that’s why we need an Assembler that
can convert the Assembly level language to Machine language so the Computer gets the instruction and
responds quickly.
The main disadvantage of this language is that it is written only for a single type of CPU and does not run
on any other CPU. But its speed makes it the most used low level language till today, which is used by
many programmers.
High Level Language:
A high level language is one which is closer to the human (programmer).It is easier for humans to understand and
difficult for machines to understand. It is slower in execution as compared to low level languages.
The high level languages are the most used and also more considered programming languages that helps a
programmer to read, write and maintain. It is also the third generation language that is used and also running till
now by many programmers. They are less independent to a particular type of Computer and also require a
translator that can convert the high level language to machine language. The translator may be an interpreter and
Compiler that helps to convert into binary code for a Computer to understand. There is various high level
programming languages like C, FORTRAN or Pascal that are less independent and also enables the programmer
to write a program.
The Compiler plays an important role on the Computer as it can convert to machine language and also checks for
errors if any before executing. There are several high level languages that were used earlier and also now like
COBOL, FORTRAN, BASIC, C, C++, PASCAL, LISP, Ada, Algol, Prolog and Java. It is user-friendly as the
programs are written in English using words, symbols, characters, numbers that needs to be converted to
machine code for processing.
Middle Level Language:
A middle level language is one which is closer to machine (computer) as well as to human (programmer).A
language that has the feature of both low level and high level languages come under this category. Hence, we
can say that the programming languages which have features of Low Level as well as High Level programming
languages known as "Middle Level" programming language.Moreformally, a high level language that allows you to
write low level program in it is called as middle level language.
It bridges gap between traditional machine understandable machine level language and more conventional high
level language. This programming helps in writing operation system as well as application programming.
Using a middle level language we can not only control the hardware but also we can develop application
programs. Only few languages are there which contains both the characteristics of a high and low level language.
C programming languages is the best example of Low Level Programming languages as it has features of low
level and high level programming languages both.
Some Popular Programming Languages
Some popular high-level languages are described below:
FORTRAN
FORTRAN, or FORmulaTRANslation, was developed by IBM in 1954 and was the first high-level
language .Originally designed to express mathematical formulas, it is still the most widely used
language for mathematical, scientific, and engineering problems. It is also useful for complex
business applications, such as forecasting and modeling. However, because it cannot handle a
large volume of input/output operations or file processing, it is not used for more typical problems.
The newest version of FORTRAN is FORTRAN 90.
Advantages
1. FORTRAN can be handle complex mathematical and logical expressions.
2. Its statements are relatively short and simple.
3. Very fast in translating assembly language to machine code as 1 to 1 relationship.
4. FORTRAN programs developed on one type of computer can often be easily modified work
on other types.
Disadvantages
1. FORTRAN does not handle input and output operations to storage devices as efficiently as some other
high level languages.
2. It has only a limited ability to express and process non-numerical data.
3. It is not as easy to read and understand as some other high level languages.
COBOL
The name COBOL stands for Common Business Oriented Language. COBOL was introduced in
1960, after having been developed by the conference on Data Systems Languages (CODASYL), a
committee of government and industry representatives called together by the U.S.Department of
Defense. COBOL is the most frequently used business programming languages for large
computers. It is designed to store, retrieve, and process corporate accounting information and to
automate such functions as inventory control, billing, and payroll.
The most significant attribute of COBOL is that it is extremely readable; even if you know nothing
about programming, you may still understand what the program does.
Advantages
1. It is machine independent.
2. It’s English like statements are easy to understand, even for a non-programmer.
3. It can handle many files, records and fields.
4. It easily handles input/output operations.
Disadvantages
1. Because it is so readable, it is wordy. Thus, even simple programs are lengthy, and programmer
productivity is slowed.
2. It cannot handle mathematical processing.
BASIC
Beginner's All-Purpose Symbolic Instruction Code (BASIC) is a high-level and simple programming
language that was developed by DR.Thomas Kurtz and DR.John Kemeny at Dartmouth College in
1965 for use in training their students. By the late 1960s, it was used in academic settings on all
kinds of computers, from mainframe to PCs.
BASIC is the most popular microcomputer language and is considered the easiest programming
language to learn. Although it is available in compiler form, the interpreter form is more popular with
first time and casual user and computer can communicate with each other during the writing and
running of the program. Several versions of BASIC are available such as GWBASIC, Quick BASIC
and Visual BASIC.
Advantages
1. The primary advantage of BASIC is its ease of use.
Disadvantages
1. Its processing speed is relatively slow, although compiler versions are faster than interpreter version.
2. There is no one version of BASIC, although in 1987 ANSI adopted a new standard that eliminates
portability problems that is problems with running it on different machine.
PASCAL
Pascal is a procedural programming language that supports structured programming and data
structures to encourage good programming practices. Pascal was originally developed in 1970 by
Niklaus Wirth and is named after the famous French mathematician Blaise Pascal.
While Pascal is a reliable and efficient programming language, it is mainly used to teach
programming techniques. Pascal simplicity, elegance, and embodiment for structured programming
principles have made it quite popular with computer scientists and students, scientific programmers,
and microcomputers users.
Advantages
1. Pascal is easy to learn.
2. It has extensive capabilities for graphic programming.
3. It is excellent for scientific use.
Disadvantages
1. Pascal has limited input/output programming capabilities, which limits its business applications.
C:A Portable Language
C is a powerful programming language developed by Dennis Ritchie at AT & T Bell laboratories of
USA in 1972.
In the early ages of computer programming, there used to be special purpose programming
languages. For example COBOL (common business oriented language) was being used to develop
business application. FORTRAN (formula translation language) was being used to solve
mathematical and technical problems. Pascal language was being used to solve scientific
problems. There was a need of such kind of language which can be used in any kind of
programming as general purpose language.
C was evolved from the earlier language BCPL (Basic Combined Programming Language) which
was developed in 1967 by Martian Richards at the Cambridge University. BCPL was developed as
a language for writing system software specially operating system and compilers.
In 1970 Ken Thompson at Bell laboratories developed a language based on BCPL and called it B
language means the first letter of BCPL. Dennis Ritchie was the programmer who developed B
language further as a new language and gave it the name of “C” the second letter of BCPL.
Because it provides the advantage of both assembly language and high level language, C is often
referred to as “middle level”. It is a structured programming language and uses high level
commands, but it is also allows the programmer to interact directly with the hardware, as in
assembly language. This capability of C well suited for system programming that requires the
programmers to write extremely efficient code that is not typically needed in normal business
programming. In addition, code written in C can easily be transported from one system to another.
Advantages
1. C work well with microcomputers
2. It has a high degree of portability-it can be run without change on a variety of computers.
3. It is fast and efficient.
4. It enables the programmer to manipulate individual bits in main memory.
Disadvantages
1. C is considered difficult to learn
2. Because of its conciseness, the code can be difficult to follow.
3. It is not suited to applications that require a lot of report formatting and data file manipulation.
PL/1
PL/1 was introduced in 1964 by IBM.PL/1(for Programming Language 1) is a third generation
language designed to process both business and scientific applications. It contains many of the
best features FORTRAN and COBOL and is quite flexible and easy to learn. However, it is also
considered to have so many options as to diminish its usefulness. As a result ,it has not given
FORTRAN and COBOL ,much competition.
Today there are several versions of PL/1 and PL/M that can run on a variety of computers.
Advantages
1. PL/1 is most effective in organizations that require both scientific and commercial
applications.
Disadvantages
1. PL/1 is difficult to learn.
LOGO
Logo was developed at the Massachusetts Institute of Technology in 1967 by Seymour
Papert,usinga dialect of LISP(LISt Processing Language,1959).Logo is a third generation language
designed primarily to teach children problem-solving and programming skills. At the basis of Logo is
triangular pointer, called a “turtle”, which responds to a few simple commands such as forward, left,
and right. The pointer produces similar movements on the screen, enabling users to draw
geometric patterns and pictures on screen. Because of its highly interactive nature, Logo is used
not only by children but also to produce graphic report in business.
Advantages
1. It helps to build programming skills in children.
2. Logo is very easy to learn.
3. It has extensive capabilities for graphics programming.
Disadvantages
1. It has only a limited ability to express and process data.
Ada
Ada is an extremely powerful structured programming language designed by the U.S.Department of
defense to ensure portability of program from one application to another.Ada was named for
Countless Ada Lovelace, considered the world’s “first programmer” and was introduced in
1980.Based on Pascal; Ada was originally intended to be a standard language for weapons
systems. However, it has been used in successful commercial applications.
Advantages
1. Ada is powerful, comprehensive language applicable to a wide range of problems.
2. Because it is an structured language, modules (sections) of a large program can be written,
compiled and tested separately before the entire program is put together.
3. It has features that permit the compiler to check errors before the program is run,
programmers are more apt to write error free programs.
Disadvantages
1. Ada has a high level of complexity and difficult to learn.
2. Presently, the number of machines that can compile Ada program is limited, and this is the languages
major weakness. A few compilers that translate subsets of the full language are available for
microcomputers.
Types of programming Languages Regarding Structure
Computer languages have the following types regarding structure instruction set &
methodology of writing codes.
*
Procedure Oriented
*
Objective Oriented
*
Visual Programming
*
Procedure Oriented
A procedure language uses the traditional approach for programming using predefined and programmer defined function and procedures. The control structure plays
an important role. Procedure oriented programming means “set of procedure”, which
is a “set of functions”. Procedural can be defined as a programming model which is
derived from structured programming, based upon the concept of calling procedure.
Procedures, also known as routines, subroutines or functions, simply consist of a
series of computational steps to be carried out. During a program’s execution, any
given procedure might be called at any point, including by other procedures or itself.
In classical procedural (or structural) programming, there are techniques to write a
code that handles some general task The most important techniques of that kind are
functions (procedures or sub-routines). The large program is partitioned into functions
that each performs a specific task. The main program calls these functions, which in
turn may call other functions. The major concern of this programming is with respect
to the data. Data are passed around from one non-member function to another and
are available everywhere throughout the large program. This allows the user to
access the data directly, alter it from several points in the program and inadvertently
introduce mistakes. If one programmer changes the representation of the data in
the computer's memory by rearranging fields within a structure (record), other
functions in the program may need to be rewritten and must then be retested to
account for this change. That means the data are not well protected in procedure
oriented programming. Though local variables in a function can be accessed within
the function, they are not useful if they must be accessed by different functions.
Example
C, COBOL, PASCAL,FORTRAN,ALGOLetc.
*
Object Oriented
Object oriented programming can be defined as a programming model which is based
upon the concept of objects. Objects contain data in the form of attributes and code in
the form of methods. In object oriented programming, computer programs are
designed using the concept of objects that interact with real world. While designing
modules, we try to see whole world in the form of objects. For example a car is an
object which has certain properties such as color, number of doors, engine size,
transmission type etc. It also has certain methods such as accelerate, brake, and so
on.
Object oriented programming languages are of various types but the most popular
ones are class-based, meaning that objects are instances of classes, which also
determine their types. An objective oriented language uses classes and objects
having specific properties and methods for a comprehensive programming. It is a
better approach than a procedure oriented language.OOP safely encapsulates
collections of functions (called methods) with the data they manipulate. In other
words, the data can only be manipulated by its own functions. This feature protects
the data from rest of the program.
Example
C++, JAVA,C#,Python etc.
*
Visual Programming
A visual programming language (VPL) is any programming language that lets users
create programs by manipulating program elements graphically rather than by
specifying them textually. A VPL allows programming with visual expressions, spatial
arrangements of text and graphic symbols used either as elements of syntax or
secondary notation. A VPL provides a graphical or windows like environment for
programming. It contains visual objects like text boxes, buttons, combo boxes, lists
and forms etc. A VPL is a programming language that uses graphical elements and
figures to develop a program. A VPL employs techniques to design a software
program in two or more dimensions, and includes graphical elements within its
programming context. A VPL is also known as an executable graphics language. A
VPL enables the development of software programs by eliminating textual software
code with a series of visual graphics elements. VPL incorporates these graphical
elements as the primary context of the language arranged in a systematic order. The
graphics or icons included within a visual program serve as input, activities,
connections and/or output of the program. A visual language can be one of a few
types, such as icon-based languages, diagramming languages and form-based
language.
Example
VB6, .Net
Language Translator
Computer cannot execute programming instructions of a programming language. They work
electronically and, therefore, must represent data and instructions in binary (1s and 0s) form.
Language Translators are programs those converts or translates programming language
(high level language) into 1s and 0s, or machine language (low level language).Language
translators use two methods to translate high level language. They either compile it or
interpret it. These methods give language translators either more common names of
compilers and interpreters.),while assembler is used to translate a program written in
assembly language into machine language.
Types of Language Translators
There are three types of system software used for translating the code that a programmer writes into a
form that the computer can execute (i.e. machine code). Theseare:
1. Assemblers
2. Compilers
3. Interpreters
Source Code is the code that is input to a translator.
Executable code is the code that is output from the translator.
1. Assembler
An Assembler is a program that converts assembly language program into machine language. Computer
does understand only machine language, assembly facilitate programmers to write programs easily but still
needs to convert the assembly language program into machine understandable form. The assembler is
language translator for low level programming language.
An assembler is like a compiler for the assembly language but interactive like an interpreter. Assembly
language is difficult to understand as it is a low-level programming language. An assembler translates a
low-level language, an assembly language to an even lower-level language, which is the machine code.
The machine code can be directly understood by the CPU.
Source
Code
Executable
Code
Assembly Process
Advantages of a Assembler
1. Very fast in translating assembly language to machine code as 1 to 1 relationship.
2. The symbolic programming is easier to understand thus time-saving for the programmer.
3. It is easier to fix errors and alter program instructions.
4. Efficiency in execution just like machine level language.
Disadvantages of a Assembler
1. It is machine dependent, cannot be used in other architecture.
2. A small change in design can invalidate the whole program.
3. It is difficult to maintain.
2.Compiler
A Compiler is a program that translates a high level language into machine code.
It translate whole
high level language program at once into machine language before it is executed.
A program written by a programmer in a high level language is called a source program. After this source
program has been converted into machine language by a compiler, it is referred to as an object program.
The object program is saved as program file ready for execution at any time desired. As shown in figure
the input to a compiler (program) is a source program written in a high level language and its output is an
object program which consists of machine language instructions. Note that the source program and the
object program are the same program, but at different stages of development.
High level language
program
Source
Code
INPUT
Compiler
Compiler
OUTPUT
Machine language
program
Executable
Code
A compiler can translate only those source programs which have written in the language for which the
computer is meant. For example, a C compiler is only capable of translating source programs which have
been written in C and, therefore, computer requires a separate compiler for each high level language.
While translating a given program, the compiler analysis each statement in the source program and
generates a sequence or machine instructions which, when executed, will precisely carry out the
computation specified in the statement. As the compiler analysis each statement, it uncovers certain
types of errors. These are referred to as diagnostic errors. The errors listed are syntax (or “language”)
errors.
The compiler can diagnose the following kinds of errors in a source program.
 Illegal characters.
 Illegal combinations of characters.
 Improper sequencing of instructions in a program.
A source program containing an error diagnosed by the compiler will not compile into an object program.
The compiler will print out a suitable message indication this, along with a list of error message which
indicate the type of errors committed. The error diagnostic is an invaluable aid to the programmer.
Examples of syntax error include the use of a variable name that contains too many characters writing
GO TO STEP -10 when the programmer used the name STEP 10 without a hyphen when labeling the
instruction, and violating punctuation rules of a language. Logic errors are not listed during compilation.
An example of a logic error is using an ADD instruction instead of a SUBTRACT instruction in a COBOL
program. Even though both instructions are valid, very different results will be obtained during program
execution. Logic error can only be detected by testing the program.
Advantages of a Compiler
1. Fast in execution
2. The object/executable code produced by a compiler can be distributed or executed without
having to have the compiler present.
3. The object program can be used whenever required without the need to of re- compilation.
Disadvantages of a Compiler
1. Debugging a program is much harder. Therefore not so good at finding errors
2. When an error is found, the whole program has to be recompiled
3. Interpreter
An Interpreter is a program that translates high-level sourcecode into executable code. However the
difference between a compiler and an interpreter is thatan interpreter translates one line at a time and
then executes it: no object code is produced, and so the program has to be interpreted each time it is to
be run.
Source
Code
Interpreter
Get next instruction
Executable
Code
An interpreter is program that translates a high level programming language into machine language
during the actual step-by-step execution of a program. Translation and execution alternate for each
statement encountered in the high level language program. In other words, an interpreter translates one
instruction, and the control unit executes the resulting machine language, the next instruction is
translated, and the control unit executes the machine language instruction, and so on. If the program is
run seven times a day, the programming language is reinterpreted seven times.
In case of a compiler, the whole source program is translated into an equivalent machine language
program. The object program, thus obtained, is permanently saved for future use and is used every time
the program is to be executes. So repeated compilation is not necessary for repeated execution of a
program. However, in case of an interpreter, no object program is saved for future use because the
translation and the execution process alternate. The next time an instruction is used; it must once again
be interpreted and translated into machine language. For example, during the repetitive processing of the
instructions within a loop, each instruction in the loop will have to be reinterpreted every time the loop is
executed.
Interpreters are often employed with microcomputers. The advantage of an interpreted over a compiler is
fast response to changes in the source program. The interpreter eliminates the need for a separate
compiling run after each program change to add features or correct errors. Moreover, a compiler is a
complex program compared to an interpreter. Interpreters are easy to write and they do not require large
memory space in the computer. The interpreter, however, is a time consuming translation method
because each statement must translated every time it is executed form the source program. Thus, a
compiled machine language program runs much faster, than an interpreted program. Ordinary
microcomputer BASIC is usually interpreted BASIC.
Advantages of an Interpreter
1. Good at locating errors in programs
2. Debugging is easier since the interpreter stops when it encounters an error.
3. If an error is deducted there is no need to retranslate the whole program
Disadvantages of an Interpreter
1. Rather slow
2. No object code is produced, so a translation has to be done every time the program is running.
3. For the program to run, the Interpreter must be present
Download