Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
386 views

Chapter 3 - Computer Programming Languages

This document discusses programming languages and their categorization. It begins by defining what constitutes a programming language and noting that there are different levels: machine language, assembly language, and high-level languages. Machine language uses binary and is difficult for humans, while assembly language uses mnemonics making it easier for humans but still needs translation. High-level languages are most abstract and portable across machines. They are translated into machine code by compilers or interpreters.

Uploaded by

Freddy Mutua
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
386 views

Chapter 3 - Computer Programming Languages

This document discusses programming languages and their categorization. It begins by defining what constitutes a programming language and noting that there are different levels: machine language, assembly language, and high-level languages. Machine language uses binary and is difficult for humans, while assembly language uses mnemonics making it easier for humans but still needs translation. High-level languages are most abstract and portable across machines. They are translated into machine code by compilers or interpreters.

Uploaded by

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

INTRODUCTION TO PROGRAMMING & ALGORITHMS

Chapter 3: Programming Languages

3.1. Introduction
What is a Programming Language
There are many definitions of what constitutes a programming language, and none of these is the
‘correct’ answer. 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.
1) A programming language has been defined as a tool to help the programmer.
2) A way of writing that can be read by both a human being and a machine.
3) A sequence of instructions for the machine to carry out.
4) A way for a human being to communicate with a machine that is unable to understand
natural language.
5) 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.
6) 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.

3.2. Categories of Programming Languages


There are three categories / levels of programming languages;
1) Machine language (low level language)
2) Assembly (or symbolic) language
3) Procedure-oriented language (high level language)

3.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.

Chapter 3: Programming Languages Page 1


3.2.2. Assembly Language
Introduced in 1950s, reduced programming complexity and provided some standardization to
build and applications. 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;
1) Mnemonic code; used in place of the operation code part of the instruction eg SUB for
substract, which are fairly easy to remember
2) 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.
3) 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


1) It is easy to locate and identify syntax errors, thus it is easy to debug it.
2) It is easier to develop a computer application using assembly language in comparison
with machine language
3) Assembly language operates very efficiently.

3.2.3. High level 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. 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;
1) Procedure-oriented languages (third generation)
2) Problem-oriented languages (fourth generation)
3) 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.

Chapter 3: Programming Languages Page 2


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.

3.3. 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

3.4. High Level language Translation


High level languages need to be translated into machine language which is the computer
language. The translation is referred to as the Compilation Processes and is done by a
1) Compiler or
2) Interpreter

3.4.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.
Characteristics of a Compiler:
1) Translates the source program code into machine code
2) Includes linkages for closed sub-routine

Chapter 3: Programming Languages Page 3


3) Allocates areas of main storage
4) Produces the object program.
5) Produces a printed copy (listing) of the source code and object code
6) Produces a list of errors found during compilation.

Characteristics of Compiler compilation process


1) 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.
2) 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

3.4.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;
1) Handling user commands in an interactive system
2) Debugging programs as they run (removing program faults).
3) Handling software produced for or by a different computer.

3.5. 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.

Chapter 3: Programming Languages Page 4


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
Analysis Machine
Code Code

3.6. Evaluating Programming Languages


Programming languages can be evaluated from a number of viewpoints/criteria, depending on
either the programmer, the environment in which the programmer works or the standards of the
organization. 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. 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.
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.

Chapter 3: Programming Languages Page 5


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.

3.7. 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.
1) The first generation of languages was machine language. Instructions and addresses were
numerical. These programs were linked to the machine they were developed on.
2) 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.
3) 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.
4) 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.
5) 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).

3.8 Common Programming Language Descriptions


The development histories of some languages are interesting, as are their general capabilities. Here are
descriptions of the most common languages in use today.
1) Ada
Ada is a general-purpose, high-level programming language based on Pascal. It was developed under
the aegis of the Department of Defense and is especially well suited to real-time and embedded
systems. Ada emphasizes data abstraction and information hiding and forces you to differentiate
between the public and private parts of each class and package. “Ada” was chosen as the name of the
language in honor of Ada Lovelace, a mathematician who is considered to have been the world’s first
programmer. Today, Ada is used primarily in military, space, and avionics systems.
2) Assembly Language
Assembly language, or “assembler,” is a kind of low-level language in which each statement
corresponds to a single machine instruction. Because the statements use specific machine
instructions, an assembly language is specific to a particular processor. Assembler is regarded as the

Chapter 3: Programming Languages Page 6


second generation language. Most programmers avoid it unless they’re pushing the limits in
execution speed or code size.
3) C
C is a general-purpose, mid-level language that was originally associated with the UNIX operating
system. C has some high-level language features, such as structured data, structured control flow,
machine independence, and a rich set of operators. It has also been called a “portable assembly
language” because it makes extensive use of pointers and addresses, has some low-level constructs
such as bit manipulation, and is weakly typed.

C was developed in the 1970s at Bell Labs. It was originally designed for and used on the DEC PDP-
11—whose operating system, C compiler, and UNIX application programs were all written in C. In
1988, an ANSI standard was issued to codify C, which was revised in 1999. C was the de facto
standard for microcomputer and workstation programming in the 1980s and 1990s.
4) C++
C++, an object-oriented language founded on C, was developed at Bell Laboratories in the 1980s. In
addition to being compatible with C, C++ provides classes, polymorphism, exception handling,
templates, and it provides more robust type checking than C does. It also provides an extensive and
powerful standard library.
5) C#
C# is a general-purpose, object-oriented language and programming environment developed by
Microsoft with syntax similar to C, C++, and Java, and it provides extensive tools that aid
development on Microsoft platforms.
6) Cobol
Cobol is an English-like programming language that was originally developed in 1959–1961 for use
by the Department of Defense. Cobol is used primarily for business applications and is still one of
the most widely used languages today, second only to Visual Basic in popularity (Feiman and Driver
2002). Cobol has been updated over the years to include mathematical functions and object-oriented
capabilities. The acronym “Cobol” stands for COmmon Business-Oriented Language.
7) Fortran
Fortran was the first high-level computer language, introducing the ideas of variables and high-level
loops. “Fortran” stands for FORmula TRANslation. Fortran was originally developed in the 1950s
and has seen several significant revisions, including Fortran 77 in 1977, which added block-
structured if-then-else statements and character string manipulations. Fortran 90 added user-defined
data types, pointers, classes, and a rich set of operations on arrays. Fortran is used mainly in scientific
and engineering applications.
8) Java
Java is an object-oriented language with syntax similar to C and C++ that was developed by Sun
Microsystems, Inc. Java was designed to run on any platform by converting Java source code to byte
code, which is then run in each platform within an environment known as a virtual machine. Java is
in widespread use for programming Web applications.
9) JavaScript
JavaScript is an interpreted scripting language that was originally loosely related to Java. It is used
primarily for client-side programming such as adding simple functions and online applications to
Web pages.
10) Perl
Perl is a string-handling language that is based on C and several UNIX utilities. Perl is often used for
system administration tasks, such as creating build scripts, as well as for report generation and

Chapter 3: Programming Languages Page 7


processing. It’s also used to create Web applications such as Slashdot. The acronym “Perl” stands for
Practical Extraction and Report Language.
11) PHP
PHP is an open-source scripting language with a simple syntax similar to Perl, Bourne Shell,
JavaScript, and C. PHP runs on all major operating systems to execute server side interactive
functions. It can be embedded in Web pages to access and present database information. The
acronym “PHP” originally stood for Personal Home Page but now stands for PHP: Hypertext
Processor.
12) Python
Python is an interpreted, interactive, object-oriented language that runs in numerous environments. It
is used most commonly for writing scripts and small Web applications and also contains some
support for creating larger programs.
13) SQL
SQL is the de facto standard language for querying, updating, and managing relational databases.
“SQL” stands for Structured Query Language. Unlike other languages listed in this section, SQL is a
“declarative language,” meaning that it does not define a sequence of operations, but rather the result
of some operations.
14) Visual Basic
The original version of Basic was a high-level language developed at Dartmouth College in the
1960s. The acronym BASIC stands for Beginner’s All-purpose Symbolic

Top Requested Programming Languages in Computer Occupations


Programming Language Type
1 SQL Database Language
2 JAVA Programming Language
3 ORACLE Database Language
4 C# Programming Language
5 JAVA-SCRIPT Programming Language
6 PYTHON Programming Language
7 JQUERY Programming Language
8 C++ Programming Language
9 Git Programming Language
10 PERL Programming Language
11 POWERSHELL Programming Language

Chapter Review Questions


1. Describe the General 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

Chapter 3: Programming Languages Page 8

You might also like