CS150 - Unit 2 - Computer Programming Languages
CS150 - Unit 2 - Computer Programming Languages
Introduction to
Programming Fundamentals
Unit 2
Computer Programming languages
1
Objectives
• Describe the characteristics of machine language and
the languages used to create programs
• Outline the generations of computer programming
languages
• Explain the relationship between High and low level
programming languages and the need for translators
• Identify the types of translators used in programming
(assemblers, compilers and interpreters)
2
Introduction
3
What is a programming language?
• A programming language is a notation for
specifying a sequence of operations to be
carried out by a computer
• Programming languages are artificial languages
created to tell the computer what to do
• They consist of a vocabulary and a set of
grammatical rules for instructing a computer
4
Types Of Programming Languages
• Classification by level
• Low level
• are closer to the computers instruction set e.g Machine language,
Assembly language
• High Level:
• instruction set is more compatible with human languages and human
thought processes e.g C++, Java, Python, C, C#, Swift, Kotlin ….
• Classification by purpose
• Special purpose: for solving a finite set of problems e.g. LISP,
PROLOG used in Artificial Intelligence
• General Purpose: solving problems is a variety of application
domains
• Classification by generation
• 1st to 5th Generation
5
Low Level High Level
• low level languages is that they are machine • Machine independent
specific • Easy to learn to learn
• Difficult to learn or understand • Less code is needed to solve problems
• Requires many lines of code • a single instruction in a high-level language will be
equivalent to several instructions in machine language
• Not portable
• Portable
• Memory efficient
• Not memory efficient
6
Common Features of programming languages
• A place for storing data. e.g variables, arrays, lists
• Rules for writing programs in that programming language
• Control statements – which are building blocks for logic implementation.
• Most support Object Oriented Programming (OOP).
• Operators. Operators are used execute mathematical operations.
• a facility to write programs, functions and procedures
• A facility to write libraries. Libraries are themselves programs, which can be used in
other programs.
• support exception handling ( way to identify errors and generate appropriate
messages)
• built in functionalities, provided as classes and functions.
• Compiler or interpreter and memory handling features.
7
Machine Language (1st Generation)
• A low level language
• consists of the numeric codes
• codes are strings of 0s and 1s, or
binary digits (“bits”
• use some bits to represent operations,
such as addition, and some to represent
operands, or perhaps the location of
the next instruction
• difficult to read and write
• Machine code programs are very
efficient
8
Assembly Language (2nd Generation)
• Low level language
• one level above machine language
• uses short mnemonic codes
(abbreviations) for instructions (ADD
A,B;)
• blocks of data (operands) may be
referred to by name or machine
addresses
• An assembler (Translator) is required
to convert the instructions to the
appropriate sequence of 1s and 0s
• easier to use than machine language,
but still more difficult to use than
higher level languages
9
High Level Language (3rd Generation) 3GL
• also called procedural language
because of the fact that they are
designed to express the logic
procedures to solve general
problems
• Use English-like words that humans
can understand easily, to write
instructions
• each language can use either an
interpreter or a compiler to convert
the instructions to machine code
10
Problem-oriented Languages: 4 th Generation
• aka 4GLs – 4th generation languages are very high
level languages designed to make it easy for people
to write programs
• designed to tackle specific problems, such as financial
or statistical analysis, data storage
• Examples: SQL, Foxpro, Focus and Code Generators
• Easy to understand & learn, less time required for
application creation, it is less prone to errors
• Memory consumption is high, has poor control over
Hardware, less flexible.
11
Natural Languages and Visual
th
Programming: 5 Generation
• incorporates the concepts of artificial intelligence to allow direct human
communication
• would enable a computer to learn and to apply new information as
people do
• we make computers learn to solve any problem
• Visual programming languages are also part of 5GLs
• Examples: PROLOG, LISP, e.tc
• Machines can make decisions, programmer effort reduces to solve a
problem, Easier than 3GL or 4GL to learn and use
• Complex and long code, more resources are required (e.g Parallel
processing) & they are expensive too
12
Need For a Translator
• A program that is written in a high level language must,
however, be translated into machine language before it can be
executed
• There are two types of translators
• Compilers
• Compilers translate the entire program into machine language before
executing any of the instructions
• Interpreters
• computer program that performs the same functions as the compiler, but
instead of converting an entire program at once, the interpreter converts
each high-level program statement into machine code one by one
• programs which are compiled run faster compared to those
which are interpreted. This is because the interpreter still does
the translation during run time, as opposed to the compiler which
does no translation during runtime
13
Compiler Vs Interpreter
• A compiler takes the entire • An interpreter takes a single line
program in one go. of code at a time.
• The compiler generates an • The interpreter never produces
intermediate machine code. any intermediate machine code.
• The compiler produces an output • The interpreter does not produce
program (.exe) that can be any output program. Therefore,
executed independently of the the execution requires a source
source program. program every time.
• It is a two-step process as the • It is a one-step process because
program execution is segregated the execution process is part of
from the compilation. Execution the interpretation that is done
begins only after the entire line by line.
source-program is compiled.
14
Compiler Vs Interpreter cont.
• The interpreter requires less memory
• The compiler needs more memory to
because there is no such process of
create an intermediate object code.
creating an intermediate object code.
• We cannot change or modify anything in
the compiled program. To make changes, • The interpreter uses the source code every
time and works line by line; Therefore, we
we have to change the source code.
can easily make changes.
• The compiler displays all errors after
compilation, which complicates the error • The interpreter displays the errors of each
line one by one, if any, making it easier to
detection and removal process.
detect and remove errors.
• The compiler is best suited for the
production environment. • An interpreter is best suited for a software
development environment.
• The compiler is used by programming
languages such as C, C ++, C #, Scala, • An interpreter is used by programming
languages such as Python, PHP, Perl, Ruby,
Java, etc.
etc.
15
Syntax and semantics
• Syntax refers to the structure/form of the code that a
specific programming language specifies
• It does not have to do anything with the meaning of the
statement.
• A statement is syntactically valid if it follows all the rules.
• It is related to the grammar and structure of the
language.
• Semantics deal with the meaning assigned to the
symbols, characters and words
16
Exercise
1. What is a programming language?
2. Explain HLL and LLL highlighting the difference between the
two
3. Explain why high level languages need a translator. Discuss
the types of translators used in high level languages
4. Discuss the common features of programming languages.
5. Discuss the two elements of programming languages:
semantics and syntax
6. Discuss the five generations of programming languages
17