You are on page 1of 26

Programming Languages

University of Zimbabwe

 Facilitator: G. Mhlanga
 +263713319506
 14/09/2023
Programming Languages
What is a computer program?
 A set of instructions on how to execute a task
 Task executed by computer
 Programming language is a way to instruct a computer

 A computer is just a machine (bare, dumb) – its advantage


 Just a combination of millions of switches
 Machine understands machine language (binary – 0 and 1), humans
understand human languages
 Programming language plays intermediary role between the two
 To command a computer there is need to understand the switches and set
them as required
Why study programming languages?

 improve use of existing languages


 increase vocabulary of useful programming constructs
 to allow for better choice of programming language
 e.g. Applications with numerical calculations: C, FORTRAN
 Applications with decision making: LISP, Prolog, ML
 Internet applications: Perl, Java
 make it easier to learn a new language e.g. C, C++, Java
 make it easier to design new languages e.g. many new languages are
based on C or Pascal as implementation models
History of programming languages

Year Activity
1883 First programming language developed by Ada Lovelace and Charles Babbage working together on the
Analytical Engine

1949 Assembly language first used as a type of programming language


1952 Alick Glennie developed Autocode considered to be the first compiled language
1957 John Backus created FORTRAN, a computer programming language for working with scientific,
mathematical and statistical projects

1958 Algol was created as an algorithmic language. Later used as a precursor to languages like Java and C
1959 COBOL created by Dr. Grace Murray Hopper
1959 Lisp created by John McCarthy for use in artificial intelligence and research
1964 BASIC created by John G Kemmeny and Thomas Kurtz for students without a technical background
1970 Niklaus Wirth developed Pascal
1972 SQL developed for IBM by Donald Chamberlin and Raymond Boyce
1978 MATLAB developed by Cleve Moler for writing math programs
1983 Brad Cox and Tom Love created Objective-C
1983 Bjarne Stroustrup created C++
1987 Perl was develop by Larry Wall as a scripting language
History of prog languages (cont’d)
1990 Haskell was developed as a functional programming language
1991 Python developed by Guido Van Rossum
1991 Visual Basic developed by Microsoft which introduced the drag-and-drop
concept
1993 Ross Ihaka and Robert Gentleman developed R for statisticians
1995 Java developed by Sun Microsystems, originally intended to run on hand-held
devices
1995 Rasmus Lerdorf developed PHP for web development
1995 Yukihiro Matsumoto developed Ruby as an all-purpose programming language
1995 Brendan Eich developed JavaScript to enhance web browser interactions
2000 C# developed by Microsoft, combining features from C# and Java
2003 Martin Odersky created Scala
2003 James Strachan and Bob McWhirter developed Groovy as an offshoot of Java
2009 Google developed Go
2014 Apple developed Swift
Categories of programming languages
1. Low-level languages
 Provides no abstraction from the hardware.
 Represented by 0s and 1s.
 Languages under this category are machine language and assembly
language

1.1 Machine Language


 Instructions and data in the binary format (0s and 1s)
 Program creation very difficult
 Prone to errors
 Each machine has its instructions and program not portable to another
machine
 Different processor architectures use different machine codes, e.g.
PowerPC uses RISC, while an intel x86 uses CISC
Categories of prog languages (cont’d)

1.2 Assembly Language


 Contains some human readable commands such as MOV, ADD, SUB,
etc
 Problems faced in assembly language are somewhat reduced
 A translator required to convert assembly code into machine code
– the translator is known as an assembler
 Data is stored in registers, therefore assembly language is not
portable
 Slower than machine language since assembly language is a level
higher than machine language
Machine Language vs Assembly Language
Machine Language Assembly Language
Zero abstraction from hardware Comes above machine language
Not easily understood by humans Easier to read, write and maintain
Written in binary digits, 0s and 1s Written in simple English language
Does not require translator Assembler used to convert from
assembly language to machine
language
It is a first-generation programming It is a second generation
language programming language
Categories of prog languages (cont’d)
2. High-level Languages
 Closer to human languages than machine-level languages
 Allow a programmer to write programs which are independent of a
particular type of computer
 Attention is paid to the logic of the program
 A compiler required to translate a high-level language to a low-
level language
Advantages of high-level languages
 Easy to read, write, and maintain – written in English-like words
 E.g. printf(“Hello”); Console.WriteLine(“Hello”);
 Designed to overcome problems of portability – languages are
machine-independent
Categories of prog languages (cont’d)

Low-level High-level
Represented in 0s and 1s, understood User-friendly, written in simple English
by machine (machine-friendly) words

Execution takes more time Execution is fast


Assembler needed to convert to Compiler needed to convert to machine
machine code code

Machine code is not portable to another Portable to various machines


machine

It is memory efficient Less memory efficient


Difficult to debug and maintain Easier to debug and maintain
Compilation vs Interpretation

 A computer program is a set of instructions to perform a


task
 Compilers and interpreters convert human readable code
to computer readable machine code
 E.g. a recipe in a foreign language
Compiled Languages
 Converted directly to machine code, hence they tend to
be fast
 They afford the developer more control over the hardware
e.g. memory management, CPU usage
 They need a “build” step, i.e. they are manually
compiled.
 After making a change the program needs to be rebuilt
 Examples – C, C++, Rust, Go
Interpreted Languages

 The interpreter runs through the program line by line and


execute each command
 Were once significantly slower than compiled, but with
the advent of JIT compilation the gap is shrinking.
 Examples – PHP, Ruby, Python, JavaScript

NB: Some languages can have both compiled and interpreted


implementations – e.g. Python
Compilers can even contain interpreters for optimization
 Compiled languages have the advantage of faster speed of execution
than interpreted
 Compiled languages have the disadvantages of:
 Additional time needed to do compilation before testing
 Platform dependence of the generated binary code
 Interpreted languages have the advantages of:
 More flexibility – can offer features like dynamic typing and smaller
program size
 Platform independence of the code
 Interpreted languages have the disadvantages of:
 Slower speed of execution compared to compiled
Overview of Compilation Process

- Compilation process is made up of a sequence of


various phases
- Each phase takes in input in one representation and
produces output in another representation
- Each phase gets input from its previous phase
Compiler Phases

Lexical Analyzer Syntax Analyzer


Source Program

Code Optimization Intermediate Code Semantic Analyzer


Generation

Code Generation

Target Program
Phases of the compiler

Lexical Analysis
 phase is the first phase of compilation process.
 takes source code as input.
 reads the source program one character at a time and
converts it into meaningful lexemes.
 Lexical analyzer represents these lexemes in the form of
tokens.
Phases of the compiler (cont’d)

Syntax Analysis
 second phase of compilation process.
 takes tokens as input and generates a parse tree as
output.
 the parser checks that the expression made by the tokens
is syntactically correct or not.
Phases of the compiler (cont’d)

Semantic Analysis
 the third phase of compilation process.
 checks whether the parse tree follows the rules of
language.
 Semantic analyzer keeps track of identifiers, their types
and expressions.
 output of semantic analysis phase is the annotated tree
syntax.
Phases of the compiler (cont’d)

Intermediate Code Generation


 compiler converts the source code into the intermediate
code.
 Intermediate code is generated between the high-level
language and the machine language.
 The intermediate code should be generated in such a way
that it can easily be translated into the target machine
code.
Phases of the compiler (cont’d)

Code Optimization
 Code optimization is an optional phase.
 used to improve the intermediate code so that the output
of the program could run faster and take less space.
 It removes the unnecessary lines of the code and arranges
the sequence of statements in order to speed up the
program execution.
Phases of the compiler (cont’d)

Code Generation
 the final stage of the compilation process.
 takes the optimized intermediate code as input and maps
it to the target machine language.
 Code generator translates the intermediate code into the
machine code of the specified computer.
Textbook and Resources:
 Programming Language Pragmatics, third edition, Michael L. Scott, 2015.
Morgan Kaufmann Publishers, ISBN 978-0-12-374514-9. The book is available
as an online resource from the library.

You might also like