Programming Languages and Translators in Computational Thinking

 
Translators &
Facilities of
Languages
 
2.5
Unit 2: Computational Thinking, Algorithms & Programming
 
Monday, 22 July 2024
Translators & Facilities of Languages
 
Learning Objective: 
To be able to demonstrate an
understanding of translators, levels of programming
languages and IDE.
 
Success Criteria:
1.
I can 
describe
 the characteristics and purpose of
high and low level programming languages.
2.
I can 
explain
 the purpose of translators.
3.
I can 
describe
 the characteristics of an assembler, a
compiler and an interpreter.
4.
I can 
discuss
 the common tools in an IDE.
Unit 2: Computational Thinking, Algorithms & Programming
 
 
 
 
 
Programming Languages
 
There are several Generations of Programming
Languages:
Low Level
1
st
 Generation
2
nd
 Generation
High Level
3
rd
 Generation
4
th
 Generation
 
Unit 2: Computational Thinking, Algorithms & Programming
 
1
st
 Generation
 
Machine Code
Directly Executable by the processor
The Generation that “computers
understand”
Difficult to program in, hard to understand,
hard to find errors (hard to debug)
Unit 2: Computational Thinking, Algorithms & Programming
 
2nd Generation
 
Assembly Code
Uses mnemonics
Easier to program in than 2
nd
 Generation but still
difficult.
One Assembly Language instruction translates to one
Machine Code Instruction (1-1 relationship)
Needs to be translated into Machine Code for the
computer to be able to execute it
Uses an Assembler
Assembler – Assembles Assembly Language
 
Unit 2: Computational Thinking, Algorithms & Programming
 
2nd Generation
 
Despite 2
nd
 Generation being difficult to Debug it
still has its uses
Debug 
means to go through the code to search
for where/why an error has occurred
It is most commonly used to program Device
Drivers
Device Drivers 
are loaded into memory by the
Operating System and used to control the
operation of a Hardware Device e.g. Graphics
Card Drivers, Printer Drivers.
Unit 2: Computational Thinking, Algorithms & Programming
 
3
rd
 Generation
 
Easier to understand (programmer)
Easier to find errors, easier to de-bug
Uses English-Like Keywords
One instruction translates into many machine
code instructions
For example: Java, Basic, Pascal, C+
Translated using:
Compiler
Interpreter
 
 
Unit 2: Computational Thinking, Algorithms & Programming
 
4th Generation
 
Known as a Declarative Language
Facts and Rules are stated
Describes what computation should be
performed and not how to perform it
Examples include:
SQL
Expert Systems
Artificial Intelligence
Unit 2: Computational Thinking, Algorithms & Programming
Activity 3 – Identify the Generation
 
Dim Num1, Num2, Tot as Integer
Num1 = Console.Readline()
Num2 = Console.Readline()
Tot = Num1 + Num2
Console.Writelein(“Total is: “ & Tot)
 
01010101010100101010100101
01010101001111100100010000
1010100101
 
LOAD r1, c
LOAD r2, d
ADD r1, r2
DIV r1, #2
 
High Level (3
rd
 Generation)
 
Low Level (2
nd
 Generation)
 
Low Level
(1
st
 Generation – Machine Code)
Exam Question
Unit 2: Computational Thinking, Algorithms & Programming
Q11a Answers: 
 (marks in pairs) 
In high level code Instructions use
words
In machine code instructions are in
binary code
High-level code is designed to be read
by human programmers
Machine code is to be read/executed
by the computer
High level code can be
portable/translated for different
machines
Machine code is specific to a
particular machine
 
Content
 
Language Translators are used to translate a
language into a form that the will be able to directly
execute
Assemblers are used for 2
nd
 Generation
Compilers/Interpreters are used for 3
rd
Generation
Unit 2: Computational Thinking, Algorithms & Programming
 
What is a Translator?
 
translator
 is a piece of software that
converts
 
programming code 
into
 machine
code.
 
The programming code could be high level
source code or low level assembly instructions.
 
The machine code then runs in the CPU
hardware - or it is stored as a file and later
loaded in the CPU to run.
Unit 2: Computational Thinking, Algorithms & Programming
 
What are the different types of
translators?
 
There are three different types of translators which
are:
Assembler
 - converts assembly language instruction
into machine code
 
Compiler
 - converts high level source code into
machine code and stores it in an executable file
 
Interpreter
 - converts a single line of high level
source code into machine code and then
immediately runs it on the CPU.
Unit 2: Computational Thinking, Algorithms & Programming
 
Compilers
 
A compiler is a language translator that transforms
source code
 written in a 
programming language
 into
machine code (also known as object code). A compiler
produces this executable program (Object code)
Machine code consists of 0’s and 1’s and is directly
understandable by the CPU. Therefore High Level code
must be translated into Low Level code so that the
computer can understand and execute it.
A compiler will go through the entire source code in one
go, translating the entire source code at once. It will
optimise the code as it does so.
If a compiler encounters errors, it produces an error
report that it outputs along with the object code.
Unit 2: Computational Thinking, Algorithms & Programming
 
Compilers
 
Compiled code tends to
execute much quicker
than interpreted code
Compilers tend to be used
once a program
development is finished
so that the program can
then be shipped out to
customers and no
compiler is needed during
run-time. Customers
therefore will not have
access to the source code.
Unit 2: Computational Thinking, Algorithms & Programming
 
Interpreter
 
An interpreter analyses and executes each
line of a high-level language program
without looking at the entire program.
Execution will be slower than for the
equivalent compiled code as the source
code is analysed statement by statement
(line by line) during execution.
As each statement is analysed the
interpreter calls routines to carry out each
instruction. No object code is generated.
This means the program has to be
interpreted each time it is run.
The advantages of interpreters over
compilers are that a program can be
executed immediately without having to
wait for it to be compiled. If a compiler and
an interpreter exist for a high-level
language, a programmer may use the
interpreter to test sections during
development
When an interpreter is working – if it
encounters an error it will stop the
interpreting and flag up the error to the
programmer.
Unit 2: Computational Thinking, Algorithms & Programming
 
Assemblers
 
Assemblers
 convert assembly code into
machine code 
(Binary form).
 
Every CPU has an instruction set made up
of assembly language mnemonics.
 
And every CPU comes with a program
called an assembler that translates
mnemonics directly into machine code
that the CPU can read.
 
Different CPU families will require
different assemblers.
Unit 2: Computational Thinking, Algorithms & Programming
 
Exam Question Practise
 
a)
Identify two reasons why some programmers still use low-level
languages.
1.    ___________________________________________________
2.    ___________________________________________________
        
[2]
b) Explain why programmers might prefer to use an assembly
language over machine code.
        ___________________________________________________
        ___________________________________________________
        
[2]
c) State the type of translator used to translate assembly languages
into machine code.
       ___________________________________________________
        
[1]
Unit 2: Computational Thinking, Algorithms & Programming
 
 
 
 
A company specialises in writing programs using low-level languages.
Slide Note
Embed
Share

Programming languages are categorized into generations, from low-level machine code to high-level languages. Translators like assemblers, compilers, and interpreters help convert code for computer execution. Each generation has its characteristics and purposes, affecting ease of programming, debugging, and error tracing. This unit focuses on various levels of languages, understanding translators, and exploring IDE tools for effective programming.

  • Programming Languages
  • Translators
  • Computational Thinking
  • Algorithms
  • IDE

Uploaded on Jul 22, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Unit 2: Computational Thinking, Algorithms & Programming Translators & Facilities of Languages 2.5

  2. Monday, 22 July 2024 Translators & Facilities of Languages Unit 2: Computational Thinking, Algorithms & Programming Learning Objective: To be able to demonstrate an understanding of translators, levels of programming languages and IDE. Success Criteria: 1. I can describe the characteristics and purpose of high and low level programming languages. 2. I can explain the purpose of translators. 3. I can describe the characteristics of an assembler, a compiler and an interpreter. 4. I can discuss the common tools in an IDE.

  3. Unit 2: Computational Thinking, Algorithms & Programming Programming Languages There are several Generations of Programming Languages: Low Level 1st Generation 2nd Generation High Level 3rd Generation 4th Generation

  4. Unit 2: Computational Thinking, Algorithms & Programming 1st Generation Machine Code Directly Executable by the processor The Generation that computers understand Difficult to program in, hard to understand, hard to find errors (hard to debug)

  5. Unit 2: Computational Thinking, Algorithms & Programming 2nd Generation Assembly Code Uses mnemonics Easier to program in than 2nd Generation but still difficult. One Assembly Language instruction translates to one Machine Code Instruction (1-1 relationship) Needs to be translated into Machine Code for the computer to be able to execute it Uses an Assembler Assembler Assembles Assembly Language

  6. Unit 2: Computational Thinking, Algorithms & Programming 2nd Generation Despite 2nd Generation being difficult to Debug it still has its uses Debug means to go through the code to search for where/why an error has occurred It is most commonly used to program Device Drivers Device Drivers are loaded into memory by the Operating System and used to control the operation of a Hardware Device e.g. Graphics Card Drivers, Printer Drivers.

  7. Unit 2: Computational Thinking, Algorithms & Programming 3rd Generation Easier to understand (programmer) Easier to find errors, easier to de-bug Uses English-Like Keywords One instruction translates into many machine code instructions For example: Java, Basic, Pascal, C+ Translated using: Compiler Interpreter

  8. Unit 2: Computational Thinking, Algorithms & Programming 4th Generation Known as a Declarative Language Facts and Rules are stated Describes what computation should be performed and not how to perform it Examples include: SQL Expert Systems Artificial Intelligence

  9. Activity 3 Identify the Generation Dim Num1, Num2, Tot as Integer Num1 = Console.Readline() Num2 = Console.Readline() Tot = Num1 + Num2 Console.Writelein( Total is: & Tot) High Level (3rd Generation) 01010101010100101010100101 01010101001111100100010000 1010100101 Low Level (2nd Generation) LOAD r1, c LOAD r2, d ADD r1, r2 DIV r1, #2 Low Level (1st Generation Machine Code)

  10. Unit 2: Computational Thinking, Algorithms & Programming Exam Question Q11a Answers: (marks in pairs) In high level code Instructions use words In machine code instructions are in binary code High-level code is designed to be read by human programmers Machine code is to be read/executed by the computer High level code can be portable/translated for different machines Machine code is specific to a particular machine

  11. Unit 2: Computational Thinking, Algorithms & Programming Content Language Translators are used to translate a language into a form that the will be able to directly execute Assemblers are used for 2nd Generation Compilers/Interpreters are used for 3rd Generation

  12. Unit 2: Computational Thinking, Algorithms & Programming What is a Translator? A translator is a piece of software that convertsprogramming code into machine code. The programming code could be high level source code or low level assembly instructions. The machine code then runs in the CPU hardware - or it is stored as a file and later loaded in the CPU to run.

  13. What are the different types of translators? Unit 2: Computational Thinking, Algorithms & Programming There are three different types of translators which are: Assembler - converts assembly language instruction into machine code Compiler - converts high level source code into machine code and stores it in an executable file Interpreter - converts a single line of high level source code into machine code and then immediately runs it on the CPU.

  14. Unit 2: Computational Thinking, Algorithms & Programming Compilers A compiler is a language translator that transforms source code written in a programming language into machine code (also known as object code). A compiler produces this executable program (Object code) Machine code consists of 0 s and 1 s and is directly understandable by the CPU. Therefore High Level code must be translated into Low Level code so that the computer can understand and execute it. A compiler will go through the entire source code in one go, translating the entire source code at once. It will optimise the code as it does so. If a compiler encounters errors, it produces an error report that it outputs along with the object code.

  15. Unit 2: Computational Thinking, Algorithms & Programming Compilers Compiled code tends to execute much quicker than interpreted code Compilers tend to be used once a program development is finished so that the program can then be shipped out to customers and no compiler is needed during run-time. Customers therefore will not have access to the source code.

  16. Unit 2: Computational Thinking, Algorithms & Programming Interpreter An interpreter analyses and executes each line of a high-level language program without looking at the entire program. Execution will be slower than for the equivalent compiled code as the source code is analysed statement by statement (line by line) during execution. As each statement is analysed the interpreter calls routines to carry out each instruction. No object code is generated. This means the program has to be interpreted each time it is run. The advantages of interpreters over compilers are that a program can be executed immediately without having to wait for it to be compiled. If a compiler and an interpreter exist for a high-level language, a programmer may use the interpreter to test sections during development When an interpreter is working if it encounters an error it will stop the interpreting and flag up the error to the programmer.

  17. Unit 2: Computational Thinking, Algorithms & Programming Assemblers Assemblers convert assembly code into machine code (Binary form). Every CPU has an instruction set made up of assembly language mnemonics. And every CPU comes with a program called an assembler that translates mnemonics directly into machine code that the CPU can read. Different CPU families will require different assemblers.

  18. Unit 2: Computational Thinking, Algorithms & Programming Exam Question Practise A company specialises in writing programs using low-level languages. a) Identify two reasons why some programmers still use low-level languages. 1. ___________________________________________________ 2. ___________________________________________________ b) Explain why programmers might prefer to use an assembly language over machine code. ___________________________________________________ ___________________________________________________ c) State the type of translator used to translate assembly languages into machine code. ___________________________________________________ [2] [2] [1]

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#