0% found this document useful (0 votes)
34 views8 pages

Chapter Two

Uploaded by

n64157257
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
34 views8 pages

Chapter Two

Uploaded by

n64157257
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

CHAPTER TWO: Programming Languages

Chapter Objectives
By the end of this chapter the learner should be able to
 Define a programming language
 Describe the types of programming languages
 Differentiate and explain advantages and disadvantages of the various types of
programming languages
 Describe the High level languages translation processes
 Describe the criteria for Programming language evaluation

2.1. What is a Programming Language


There are many definitions of what constitutes a programming language, and none of these is the ‘correct’
answer. What might have defined a programming language in the 19th century would not necessarily be
detailed enough for a modern definition. Programming languages are needed to allow human beings and
computers to talk to each other. Computers, as yet, are unable to understand our everyday language or, in
fact, the way we talk about the world. Computers understand logic expressed mathematically through
what is known as machine code. Computer language consists of 1s and 0s or the binary system, which the
majority of human beings would find very difficult to communicate in. Computer languages enable
humans to write in a form that is more compatible with a human system of communication. This is then
translated into a form that the computer can understand. Here are some different ideas on what
constitutes a programming language.
 A programming language has been defined as a tool to help the programmer.
 A way of writing that can be read by both a human being and a machine.
 A sequence of instructions for the machine to carry out.
 A way for a human being to communicate with a machine that is unable to understand natural
language.
 A computer language offers a means of writing algorithms that can be understood by both human
being and machine. Machines are unable to understand natural language, so a human being uses
algorithms that are translated into machine code by the programming language. Machine code is
difficult for humans to use, so a language ‘translates’ human readable language into machine
readable form.
 A computer program offers humans a standard way of expressing algorithms to solve particular
problems. As languages offer a convention it allows other humans to read the program, and change it
if they need to.

2.2. Types of Programming Languages


There are three levels of programming languages;
 Machine language (low level language)
 Assembly (or symbolic) language
 Procedure-oriented language (high level language)

2.2.1. Machine language


The lowest-level programming language (except for computers that utilize programmable microcode)
Machine languages are the only languages understood by computers. While easily understood by
computers, machine languages are almost impossible for humans to use because they consist entirely of
numbers. It is a programming language in which the instructions are in a form that allows the computer to
perform them immediately, without any further translation being required. Instructions are in the form of
a Binary code also called machine code and are called machine instructions. Commonly referred to as the
First Generation language

2.2.2. Assembly Language


Introduced in 1950s, reduced programming complexity and provided some standardization to build and
applications. Also referred to second generation language. The 1 and 0 in machine language are replaced
by with abbreviations or mnemonic code. It consists of a series of instructions and mnemonics that
correspond to a stream of executable instructions. It is converted into machine code with the help of an
assembler. Common features includes;
 Mnemonic code; used in place of the operation code part of the instruction eg SUB for substract,
which are fairly easy to remember
 Symbolic Addresses which are used in place of actual machine addresses. A programmer can choose
a symbol and use it consistently to refer to one particular item of data. Example FNO to represent
First No.
 The symbolically written program has to be translated into machine language before being used
operationally. A 1 to 1 translation to machine language, ie one symbolic instruction produces one
machine instruction/code.
Advantages of Assembly language over machine language
 It is easy to locate and identify syntax errors, thus it is easy to debug it.
 It is easier to develop a computer application using assembly language in comparison with machine
language
 Assembly language operates very efficiently.

2.2.3. High level language


A Machine independent and a Problem oriented (POL) programming language. High level language is
portable across different machine types (architectures); The machine independence of the high level
languages means that in principle it should be possible to make the same high-level language run on
different machines. It reflects the type of problem solved rather than the features of the machine.

High level languages are more abstract, easier to use and more portable across platforms as compared to
low-level programming languages. A programmer uses variables, arrays or Boolean expressions to
develop the logic to solve a problem. Source programs are written in statements akin to English. A high
level language code is executed by translating it into the corresponding machine language code with the
help of a compiler or interpreter. High level languages can be classified into the following categories;
 Procedure-oriented languages (third generation)
 Problem-oriented languages (fourth generation)
 Natural languages (fifth generation).

Procedure languages.
High-level languages designed to solve general-purpose problems, example BASIC, COBOL,
FORTRAN, C, C++ and JAVA. They are designed to express the logic and procedure of a problem.
Though the syntax of the languages may be different, they use English-like commands that are easy to
follow. They are portable.

Problem-oriented languages
Problem-oriented languages also known as Fourth Generation Languages (4GL) are used to solve specific
problems and includes query languages, report generators and Application generators which have simple
English like syntax rules. The 4GLs have reduced programming efforts and overall cost of software
development. They use either visual environment or a text environment for program development similar
to that of third-generation languages. A single statement of the 4GL can perform the same task as multiple
line of a third-generation language. It allows a program to just drag and drop from the toolbar, to create
various items like buttons, text boxes, label etc. A program can quickly create a prototype of the software
applications

Natural Languages
Natural languages widely known as fifth generation languages, are designed to make a computer to
behave like an expert and solve problems. The programmer just needs to specify the problem and the
constraints for problem solving. Natural languages such as LISP and PROLOG are mainly used to
develop artificial intelligence and expert systems.

Features of high level language


 Extensive vocabulary of words, symbols and sentences
 Whole sentences are translated into many machine codes instructions
 Portable across different machine types (architectures)
 Libraries of macros and sub-routines can be incorporated
 As they are problem oriented, the programmer is able to work at least to some extent independently of
the machine.
 Have a set of rules that must be obeyed.
 Syntax: the structure of the statements and the grammatical rules governing them. Grammatical
rules that govern the way in which words, symbols, expressions and statements may be formed
and combined.
 Semantics: the meaning of the statements written in the language. The rules that governs its
meaning. – what happens when the program is executed/run most are standardized by ISO/ANSI
to provide an official description of the language

2.3. High Level language Translation


High level languages need to be translated into machine language which is the computer language. The
translation is done by a Compiler or Interpreter

2.3.1. Compiler
A compiler is a manufacturer specifically written computer program which translates (or compiles) a
source code computer program that translates the source code written in a high level language into the
corresponding object code of the low level language. The translation process is called compilation. The
entire high level source code / program is converted into the executable machine code file prior to the
object program being loaded into main memory and executed. Translation done only ones and the object
program can be loaded into the main storage and executed. A program that translates a low-level language
into a high level language is called a Decompiler. Compiled languages includes C, C++, COBOL,
FORTRAN etc.

Compilers are classified into single-Pass compilers and Multi-pass compilers. Single-pass compilers are
generally faster than multi-pas compilers, but multi-pass compilers are required to generate high quality
code

A Compiler:
 Translates the source program code into machine code
 Includes linkages for closed sub-routine
 Allocates areas of main storage
 Produces the object program.
 Produces a printed copy (listing) of the source code and object code
 Produces a list of errors found during compilation.

2.3.2. Interpreter:
The interpreter is a translation program that converts each high-level language statement into the
corresponding machine code. The translation process is carried out just before the program statement is
executed. Instead of the entire program, one program statement at a time is translated and executed
immediately. When using an interpreter, the source code translated every time the program is executed

The commonly interpreted languages include BASIC and PERL. Though interpreters are easier to create
as compared to compilers, the compiled languages can be executed more efficiently and are faster.
Interpreters are appropriate in;
 Handling user commands in an interactive system
 Debugging programs as they run (removing program faults).
 Handling software produced for or by a different computer.

2.4. Computer Program Compilation Process


A computer program compilation process involves the following five stages;
1. Lexical analysis: the source program is transformed into tokens. During the transformation all
whitespaces and comments are discarded. All character sequences that do not form valid tokens are
discarded and an error message is generated.
2. Syntactical analysis: analysis to ensure the program syntax is appropriate to the language. Failure
results in an error message been generated.
3. Type / Semantic checking: responsible for ensuring that the compile-time semantic rules of the
language are enforced. An error message is generated if the semantic rules are violated
4. Code optimization: improves the intermediate code based on the target machine architecture
5. Code generation: target machine code is generated.

The first three stages are concerned with finding and reporting errors to the programmer, while the last
two are concerned with generating efficient machine code to run on the targeted computer.

Lexical Syntaticical Type / Code Code


Source Analysis Analysis Semantic Optimization Generation Machine
Analysis
Code Code

2.5. Evaluating Languages


Programming languages can be evaluated from a number of viewpoints, depending on either the
programmer, the environment in which the programmer works or the standards of the organisation. When
developing software, a programmer should consider which language is most suitable to the task, rather
than relying on a language with which they are familiar. You wouldn’t want to use a spreadsheet to
develop a database. All the features of the language need to be considered rather than just one particular
feature. A wrong choice can mean that the software has to be re-written, which can be very frustrating and
time consuming.

There are a number of different ways that the programmer can think about the design of the system, from
the top-down of structured programming to object oriented design issues. Some languages are geared
towards one particular style of design, whilst others incorporate many types. Each of these language
paradigms enables the programmer to consider the problem from a different viewpoint. There are a few
basic questions that can be asked to help when making these decisions:

1. How readable is the language, to humans? If parts of the program are going to be read or altered
separately from the entire program is might be worth considering how legible they are going to be. It
is also useful to consider the length of names allowed in the language, for instance an early form of
Fortran allowed for only 6 characters. This can lead to clumsy abbreviations that are difficult to read.
Statements such as GO TO, FOR, WHILE and LOOP have increased the readability of programs,
and lead to neater programs. These statements also affect the syntax or grammar.
2. When it comes to writing the program, how easy is it to write the program in this particular
language? A programming language that is easy to write in can make the process easier and faster. It
may help to reduce mistakes. FOR loops and other types of statement allow the programmer to write
much simpler code. This will save time and money, and also make the program smaller.
3. How reliable is the language? Not all languages create robust programs, and some help the
programmer to avoid making errors. A program that is not robust can cause errors, and code can
‘decay’. Any language that helps the programmer to avoid mistakes will make it easier to use.
4. How much would it cost to develop using a given language? Is the language expensive to use and to
maintain? Programs may need to be updated or redeveloped, and an expensive language may make
this prohibitive.
5. How complicated is the syntax going to be? Syntax is an important consideration. Clarity and ease of
understanding are important, as is a syntax that seems logical and sensible. Errors are very likely to
occur where one area of syntax too closely resembles another, and the program may prove difficult
to debug. Some theorists reason that if it is difficult to write a program to parse the language, then it
follows that it will be problematical for the programmer to get it right.
6. Does the language have standards? Languages that have standards for writing programs have greater
readability; for instance Java has standards for naming, commenting and capitalization.

2.6. The Programming Language Generations


The language generations span many decades, and begin with the development of machine code. Each
generation adds new features and capabilities for the programmer to use. Languages are designed to
create programs of a particular type, or to deal with particular problems. Modern languages have led to
the development of completely different styles of programming involving the use of more human-like or
natural language and re-usable pieces of code.
 The first generation of languages was machine language. Instructions and addresses were numerical.
These programs were linked to the machine they were developed on.
 The second generation allowed symbolic instructions and addresses. The program was translated by an
assembler. Languages of this generation include IBM, BAL, and VAX Macro. These languages were
still dependent on the machine they were developed on.
 Third generation languages allowed the programmer to concentrate on the problem rather than the
machine they were writing for. Other innovations included structured programming and database
management systems. 3GL languages include FORTRAN, COBOL, Pascal, Ada, C, and BASIC. All
3GL languages are much easier for the human being to understand.
 4GL languages (fourth generation). These are known as non-procedural, they concentrate on what you
want to do rather than how you are going to do it. 4GL languages include SQL, Postscript, and
relational database orientated languages.
 5GL (fifth generation). These languages did not appear until the 1990s, and have primarily been
concerned with Artificial Intelligence and Fuzzy Logic. The programs that have been developed in
these languages have explored Natural Language (making the computer seem to communicate like a
human being).

Chapter Review Questions


1. Describe the C program compilation process
2. What criteria should a programmer use to evaluate a programming language
3. What are advantages of High-level languages over the Assembly language.
4. Describe the categories of the high-level languages

You might also like