0% found this document useful (0 votes)
2 views13 pages

Introduction to Elements of Programming

The document provides an introduction to programming concepts, defining computers, programs, and programming languages. It distinguishes between low-level and high-level programming languages, as well as the roles of translators, compilers, and interpreters in converting code. Additionally, it outlines the differences between compiled and interpreted languages along with exercises for further understanding.

Uploaded by

balogunjeff7
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)
2 views13 pages

Introduction to Elements of Programming

The document provides an introduction to programming concepts, defining computers, programs, and programming languages. It distinguishes between low-level and high-level programming languages, as well as the roles of translators, compilers, and interpreters in converting code. Additionally, it outlines the differences between compiled and interpreted languages along with exercises for further understanding.

Uploaded by

balogunjeff7
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/ 13

Introduction to Elements of

Programming
Godfred Kusi Fosu
What is a Computer?

• Let us see two different definitions


1. Computer is an electronic device that accepts data as input,
processes and stores the data, and retrieve information as output.
2. Computer is an electronic device for storing and processing data,
typically in binary form, according to instructions given to it in a
variable program.
What is a program?
• A computer program or just a program is a sequence of instructions, written to
perform a specified task with a computer.
• A computer requires programs to function, typically executing the program's
instructions in a central processor.
• The program has an executable form that the computer can use directly to
execute the instructions.
• The same program in its human-readable source code form, from which
executable programs are derived, enables a programmer to study and develop
its algorithms.
• The art of creating a set of instructions not for a person but for a computer, in
order to accomplish a specific task using a set of directives—a programming
language—known to both the programmer and the computer operating
system.
What is a Programming Language?
• A "programming language" is a language designed to describe a set of
consecutive actions to be executed by a computer.
• A programming language is therefore a practical way for us (humans) to give
instructions to a computer.
• The language used by the processor is called machine code. This code consists
of a series of 0s and 1s known as (binary data), is difficult for humans to
understand, hence the need for intermediary languages, which can be
understood by humans, have been developed.
• These languages are then translated into machine code so that the processor
can also process it.
• All programming languages can be categorized as either low-level or high level.
Low-level Programming Language
• A low-level programming language is a programming language that provides
little or no abstraction from a computer's instruction set architecture.
• These languages can be converted to machine code without using a compiler
or an interpreter, and the resulting code runs directly on the processor.
• A program written in a low-level language can be made to run very quickly, and
with a very small memory footprint.
• Low-level languages are simple, but are considered difficult to use, due to the
numerous technical details which must be remembered.
• Examples are Assembly language and Machine language.
High level Programming Language
• A high level programming language is a language which allows the use of
abstraction during programming and allows algorithms and functions to be
written without requiring detailed knowledge of the hardware used in the
computing platform.
• Higher level languages are easier to read and can typically sometimes work on
many different computer operating systems.
• Programs written in high level languages are translated into machine code via
either a compiler or an interpreter.
• Examples of high level programming languages are C, C++, Java, VB, COBOL, BASIC,
Pascal, etc.
Translator
• A translator is a computer program that translates a program written in a
given programming language into a functionally equivalent program in a
different computer language, without losing the functional or logical structure
of the original code.
• In simple terms, a translator is a special computer program that translates
programs written in high-level language or low-level language into machine
code.
• The program written in any high-level programming language (or written in
assembly language) is called the Source code and the translated machine code
is known as Object code.
• Among the common translators in programming includes compilers,
interpreters and assemblers.
Compiler
• A compiler is a computer program that translates code written in a high-level
programming language (source code) to a low-level programming language usually
known as machine/object code.
• The output of a compiler is an executable file, which is made of instructions
encoded in a specific machine code.
• Compilers designed for distinct programming languages might be quite different;
nevertheless, they all tend to accomplish a common task.
• Between the source code and the target code (object/machine code) of a compiler
involves a series of processes. It is important to note that this series of processes
might not be same among all programming languages.
• Since we shall be using C++ to compile and run our algorithms and programs, let us
consider its compilation process.
• These are parsing (C++ Preprocessor), translating (Compiler), assembling
(Assembler), and linking (Linked editor). These processes are discussed in turn in the
following points.
Compiler Cont’.
• The C++ Preprocessor: The Preprocessor accepts source code as input
and is responsible for removing comments and representing special
preprocessor directives denoted by #.
• The Compiler: The expanded source code file produced by the C++
preprocessor is translated into assembly code for the platform.
• The Assembler: The assembler creates an object code from the output of
the compiler for the platform.
• Linker or Linked Editor: The object code file generated by the assembler
is linked together with the object code files for any library functions used
to produce an executable file.
Compiler Cont’.
Interpreter
• An Interpreter is also a program that translates high-level source code into
executable code.
• However the 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.
• If the program performs a section code 1000 times, then the section is
translated into machine code 1000 times since each line is interpreted
and then executed.
Difference between Compiler and Interpreter
Compiler Interpreter

Compiler works on the complete program at once. It takes the entire Interpreter program works line-by-line. It takes one statement at a time as
program as input input

Fast in execution Slow in execution

When an error is found, the whole program has to be re-compiled If an error is deducted there is no need to retranslate the whole program

Object code is executable without the presence of the compiler Interpreter must be present before program can run

Compiler creates an object file (code) An interpreter does not create any object file (code)

It’s difficult to correct errors in compiled programs Easy to correct errors in an interpreted programs

Compiled programs take more memory because the entire object code has Interpreter does not generate intermediate object code. As a result,
to reside in memory interpreted programs are more memory efficient.

Compiler does not allow a program to run until it is completely error-free Interpreter runs the program from first line and stops execution only if it
encounters an error.
Compiled Languages Verses Interpreted Languages
• Compiled languages are programming languages whose translation (from
high level to machine code) is typically by compilers.
• Examples are, Ada, BASIC, C, C++, COBOL, Java, Lisp, etc.
• Whereas Interpreted languages are those programming languages that
typically rely on Interpreters to translate and run directly without compiling
to machine code.
• Examples are; JavaScript, PHP, VB, Perl, Python, etc.
• Chapter Exercises
1. What is a low level programming language?
2. Outline 5 differences between compiled and interpreted languages
3. Explain translators and give three examples
4. Examine the advantages and disadvantages of both compilers and
interpreters

You might also like