Introduction
to computer programming
Programming
languages are artificial languages designed to control computers and many man
hours have been spent to develop new and improved languages. There are
thousands of different programming languages, but most conform to a few basic
paradigms.
A computer programming language is a vocabulary and set of grammatical
rules for instructing a computer to perform specific tasks.
The term “programming language” usually refers to high-level languages,
such as BASIC, C, C++, COBOL, FORTRAN, Ada, and Pascal. Each language has a
unique set of keywords (words that it understands) and a special syntax for
organizing program instructions.
High-level programming languages,
while simple compared to human languages, are more complex than the languages
the computer actually understands, called machine languages.
Generally Java is
used for internet applications. C++ is a language of professional developers
and used extensively in developing operating systems. PHP is another language
used for internet applications. There is a new class of languages which are
being utilized for the mobiles. These are light weight, modular languages which
are used to design mobile applications.
Types of
programming languages
There are three (3) basic types
of computer programming languages. They are:
1. Machine
language
2. Assembly
language and
3. High-level
language.
Each of
these types of programming languages is described below.
Machine language
Machine language is the only language that a computer understands. Each
statement in a machine language program is a sequence of bits. Each bit may be
set to 0 or 1. Series of bits represent instructions that a computer can
understand. For example, the number 455 is represented by the bit sequence
111000111.
Machine language is a low-level programming language. It is easily
understood by computers but difficult to read by people. This is why people use
higher level programming languages. Programs written in high-level languages
are compiled and/or interpreted into machine language so computers can execute
them.
Assembly language
Assembly language is a representation of machine language. In other
words, each assembly language instruction translates to a machine language
instruction. The advantage of assembly language is that its instructions are
readable. For example, assembly language statements like MOV and ADD are more
recognizable than sequences of 0s and 1s. Though assembly language statements
are readable, the statements are still low-level.
A disadvantage of assembly language is that it is not portable. In
other words, assembly language programs are specific to a particular hardware.
Assembly language programs for a Mac will not work on a PC. But this can be an
advantage for programmers who are targeting a specific platform and need full
control over the hardware.
High-level language
High-level languages are what most programmers use. Languages such as
C, C++ and Java are all high-level languages. One advantage of high-level
languages is that they are very readable. The statements in these languages are
English-like. For example, you can gain a basic understanding of what a Java
program is doing by simply reading the program source code. High-level
languages use English words as statements. Loops in Java programs are indicated
by the words for, while and do.
A disadvantage of
high-level languages is that they are usually less powerful and less efficient.
Since statements are high-level, you cannot code at the bit level the way you
can with assembly language. High-level languages also need to be compiled
and/or interpreted into machine language before execution.
Examples are Java, C#, Perl, Ruby, Python, PHP and JavaScript.
Translators
A
translator is a program which converts statements (program or instructions)
written in one language to statements in another language especially to machine
language.
There are three types of
translators:
1. Assemblers
2. Compilers.
3. Interpreters.
Assembler
This is a program, which
translate assembly language into machine code. One machine instruction is
generated for each source instruction. The resulting program can only be
executed when the assembly process is completed. The assembler reserves space
for the instructions and data, replaces mnemonic operating codes by machine
codes and symbolic addresses by numeric addresses while it determines the
machine representation of constants.
Functions of the assembler
(a) It
translates mnemonic operation codes, and symbolic addresses into machine
addresses.
(b) Includes
the necessary linkages for closed subroutines and insert appropriate machine
code for macros.
(c) Allocates
area of storage.
(d) Detects
and indicates invalid source language instructions.
(e) Produces
the object program on disk as required.
(f) Produces
a printed listing of the source and object program with comments.
Compiler
A compiler translates a high
level language into machine language. The compiler translate the whole source
program into machine code or object program prior to the object being loaded
into main memory and execution. The resulting program can only be executed when
compilation is completed.
Functions of the compiler
(a) Translates
the source program statements into machine code.
(b) Includes
linkage for closed subroutines.
(c) Allocates
areas of main storage.
(d) Generates
the object program on cards, tapes or disc as required.
(e) Produces
a printed copy of the source and object program when required.
(f) Tabulates
list of errors found during program compilation. For example, the use of a word
or statement not included in the language vocabulary, the rule of syntax or
lexis.
Interpreter
Interpreter is more easily
understood by comparing them with compiler. Both compilers and interpreters are
commonly used for the translation of high-level language program but they
perform the translation in two completely different ways. The difference
between the compiler and the interpreter is in their translation process. For
the compiler, the whole of the high level language source program is converted
into machine code object program prior to the object program being loaded into
main memory for execution. This in contrast to the interpreter which deals with
the source program one instruction at a time, completely translating and
executing each instruction before it goes onto the next.
Interpreters hardly produce
object codes but call upon in-built routines instead. However, some
intermediate codes are usually produced temporarily. The interpreter does not
produce object program, it read source program, translates it and goes ahead to
execute it.
The object program provided by a compiler fastens execution than any
interpreter can do in the running of a program, the use of object program may
however pose a problem where there is an error as it is very time consuming to
discover the source of error, a compiler is capable of producing a machine code
generated by it at any time, whereas an interpreter can only execute the source
program. If a computer is used, the same program needs only to be translated
once. Thereafter, the object program can be loaded directly into main storage
and executed. However, when an interpreter is used, the source program will be
translated every time the program is executed. Execution carried out in this
way may be ten times slower than the execution of the equivalent object programs.
Functions of the interpreter
1. Handling user commands in an interactive system.
2. They debug programs as they run, that is, for each line of coding
before implemented.
3. Handling software produced for or by different computer. In this
case, the interpreter
may be essential if:
a. Two dissimilar machines are
to be connected together for operation, or
b. If software produced on an
old model and not yet converted had to be run on a new one. This procedure is
referred to as SIMULATION since the interpreter allows the new computer to
simulate the behavior of the old.
4. The interpreter can also be
used to simulate a new machine not yet provided but for which software is
already written.
No comments:
Post a Comment