Translators and facilities of languages
Unit 8 Logic and languages
Starter
• Name five programming languages
• Are there any major differences between each of them?
Objectives
• Describe the characteristics and purpose of different
levels of programming language, including:
• Low-level languages
• High-level languages
• Understand the purpose of translators
• Describe the characteristics of a compiler
and interpreter
Translators and facilities of languages
Unit 8 Logic and languages
Starter
• High-level Programming languages
• Python, Visual Basic, C#, Java, C++, PHP, Delphi, Logo
• Query languages
• SQL
• Markup languages
• HTML, XML
• Low-level Programming languages
• Assembly language
Translators and facilities of languages
Unit 8 Logic and languages
Machine code
• Computers were first invented in the 1940s
Translators and facilities of languages
Unit 8 Logic and languages
Machine code
• In the first computers, all programs were written in
machine code
• Instructions were written in binary, so a typical
instruction looked like this:
101011001001
• Each instruction did one very small task like
LOAD the value 1 into the accumulator
• Writing programs was difficult and time-consuming
Translators and facilities of languages
Unit 8 Logic and languages
Assembly language
• Assembly language allows a programmer to create
programs more easily that writing in machine code
• Each assembly language instruction maps directly to
machine code
• For example:
1000101100000100001001010011001
LDA 51
1000000000000000000000000000001
ADD #FF 01111111110000000000000000000000
0010001001000001000010010100110
STO 52 10000000000
Assembly language Machine code
means “Load the contents of memory location 51 into the
accumulator, add hexadecimal value FF and store the result
in location 52”
Translators and facilities of languages
Unit 8 Logic and languages
Assembly language
• Assembly language is processor-specific
• It has to be translated into machine code before it
can be executed
• As each instruction corresponds directly to a
machine code instruction, it is known as a
low-level language
Translators and facilities of languages
Unit 8 Logic and languages
High-level languages
• High-level languages generally have statements that
look a bit like English or Maths
area = (base * height) / 2 print(area)
• This makes these
languages easier to
learn and understand
easy to learn
and understand
Translators and facilities of languages
Unit 8 Logic and languages
High-level languages
• High-level languages also have data structures such
as arrays and records
• Many high-level languages have been especially
designed to make it as easy as possible to write
programs to solve certain types of problem
• A single statement usually translates into several machine
code instructions
• The translation is done by a program which may be
either a compiler or an interpreter
Translators and facilities of languages
Unit 8 Logic and languages
Machine independence
• A program written in a high-level language such as
Python or VB, for example, can be run on different
types of processor with very few changes, if any, to
the program statements
• A different compiler or interpreter is used for each type of
processor to translate the source code (written by the
programmer) into machine code for that processor
Translators and facilities of languages
Unit 8 Logic and languages
High- and low-level languages
Translators and facilities of languages
Unit 8 Logic and languages
High-level Advantages
• There are a number of advantages of high-level
languages, including:
• A high-level language is easier to learn
• Programs can be written faster in a high-level language
• It is easier to understand and debug a high-level language
• Given all these advantages, why do you think that
low-level languages are still used by
some programmers?
Translators and facilities of languages
Unit 8 Logic and languages
Low-level advantages
• As a programmer has direct control over how a low-
level program works they have a number
of advantages, including:
• A program written in a low-level language can run very quickly
• The code will usually require less RAM
• Statements in a low-level language can be used to control
and manipulate specific hardware components
• As such, programs such as device drivers are often
written in assembly code
Translators and facilities of languages
Unit 8 Logic and languages
Worksheet 4
• Now complete Task 1 on Worksheet 4
Translators and facilities of languages
Unit 8 Logic and languages
Compiler
• A compiler translates a high-level language into
machine code
• The code written by the programmer is called the source code
• The code produced by the compiler is called the object code
• The object code can be saved a storage drive and
run whenever required
Translators and facilities of languages
Unit 8 Logic and languages
Interpreter
• An interpreter is another type of program that
translates a high-level language into machine code
• Unlike a compiler, no object code is produced
• It translates each line of code and executes
it immediately
• If it reaches a line with a syntax error, it stops and displays an
error message
• Interpreted code can run on any computer with an
interpreter which makes it more portable
Translators and facilities of languages
Unit 8 Logic and languages
Compiler vs interpreter
Compiler Interpreter
Translates the whole program Translates and executes one
to produce object code line at a time
A compiled program executes Takes more time to execute as
faster as it is already in each instruction is translated
machine code before it is executed
No need for the compiler to be
The interpreter must be
present when the object code
installed to run the program
is run
Customers who have bought
Customers can see the source
commercial software cannot
code so could adapt it or see
see the code when they buy it
how it works
so cannot adapt it
Translators and facilities of languages
Unit 8 Logic and languages
Compiler or interpreter?
• Some languages, such as Java, are compiled into
an intermediate stage called bytecode
• The bytecode can be interpreted on many different types of
processor using an interpreter
• Javascript, used in creating web pages, is
interpreted; the source code is included in the web
page and then interpreted in the browser (e.g.
Firefox, Chrome, Internet Explorer)
Translators and facilities of languages
Unit 8 Logic and languages
Worksheet 4
• Now complete Task 2 on Worksheet 4
Translators and facilities of languages
Unit 8 Logic and languages
Plenary
• Complete the following by filling in the blanks
__________ languages include __________, VB and
Java. They need to be __________ or interpreted
before they can be run. __________ is a low-level
language. It is __________ into __________ before it
is run.
Compiled Assembly language Machine code
Python High-level assembled
Translators and facilities of languages
Unit 8 Logic and languages
Plenary
• Complete the following by filling in the blanks
High-level languages include Python, VB and Java.
They need to be compiled or interpreted before they
can be run. Assembly language is a low-level
language. It is assembled into machine code before it
is run.
Compiled Assembly language Machine code
Python High-level assembled
Translators and facilities of languages
Unit 8 Logic and languages
Copyright
© 2020 PG Online Limited
The contents of this unit are protected by copyright.
This unit and all the worksheets, PowerPoint presentations, teaching guides and other associated files
distributed with it are supplied to you by PG Online Limited under licence and may be used and copied by you
only in accordance with the terms of the licence. Except as expressly permitted by the licence, no part of the
materials distributed with this unit may be used, reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic or otherwise, without the prior written permission of PG Online Limited.
Licence agreement
This is a legal agreement between you, the end user, and PG Online Limited. This unit and all the worksheets,
PowerPoint presentations, teaching guides and other associated files distributed with it is licensed, not sold, to
you by PG Online Limited for use under the terms of the licence.
The materials distributed with this unit may be freely copied and used by members of a single institution on a
single site only. You are not permitted to share in any way any of the materials or part of the materials with any
third party, including users on another site or individuals who are members of a separate institution. You
acknowledge that the materials must remain with you, the licencing institution, and no part of the materials may
be transferred to another institution. You also agree not to procure, authorise, encourage, facilitate or enable any
third party to reproduce these materials in whole or in part without the prior permission of PG Online Limited.