OCR A Level F453: 3.3.2 The function and purpose of translators 3.3.2 Translators a. describe the need for, and use of, translators to convert source code.

Slides:



Advertisements
Similar presentations
GCSE Computing Lesson 5.
Advertisements

compilers and interpreters
Software Development Languages and Environments. Programming languages High level languages are problem orientated contain many English words are easier.
Chapter 3 Loaders and Linkers
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
Programming Types of Testing.
CPSC Compiler Tutorial 9 Review of Compiler.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
Programming Creating programs that run on your PC
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
Chapter 1 Introduction to C Programming. 1.1 INTRODUCTION This book is about problem solving with the use of computers and the C programming language.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Compiled by Benjamin Muganzi 3.2 Functions and Purposes of Translators Computing 9691 Paper 3 1.
Systems Software Operating Systems.
Activity 1 - WBs 5 mins Go online and spend a moment trying to find out the difference between: HIGH LEVEL programming languages and LOW LEVEL programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
Introduction to Programming Language CS105 Programming Language First-generation: Machine language Second-generation: Assembly language Third-generation:
Languages and Environments Higher Computing Unit 2 – Software Development.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Standard Grade Computing SYSTEM SOFTWARE CHAPTER 19.
Higher Grade Computing Studies 2. Languages and Environments Higher Computing Software Development S. McCrossan 1 Classification of Languages 1. Procedural.
Standard Grade Computing System Software & Operating Systems.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
Programming With C.
Python From the book “Think Python”
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
What am I?. Translators Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and.
What on Earth? LEXEMETOKENPATTERN print p,r,i,n,t (leftpar( 4number4 *arith* 5number5 )rightpar) userAnswerID Letter followed by letters and digits “Game.
I Power Higher Computing Software Development Development Languages and Environments.
What Do I Represent?. Translators – Module Knowledge Areas Revisiting object code When we disassemble code we can view the opcodes used This is just a.
Intermediate 2 Computing Unit 2 - Software Development Topic 2 - Software Development Languages and Environments.
What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.
A computer contains two major sets of tools, software and hardware. Software is generally divided into Systems software and Applications software. Systems.
The Functions and Purposes of Translators Translators, Interpreters and Compilers - High Level Languages.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Compilers and Interpreters
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Chapter 1: Introduction to Computers and Programming
Evolution and History of Programming Languages
Computer Basics.
History of C and basics of Programming
Topic 2: Hardware and Software
Advanced Computer Systems
Component 1.6.
Component 1.6.
14 Compilers, Interpreters and Debuggers
High or Low Level Programming Language? Justify your decision.
Component 1.6.
Introduction to programming
Lexical and Syntax Analysis
Programming Language Hierarchy, Phases of a Java Program
CSCI-235 Micro-Computer Applications
Compiler Construction (CS-636)
A451 Theory – 7 Programming 7A, B - Algorithms.
Teaching Computing to GCSE
TRANSLATORS AND IDEs Key Revision Points.
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
WJEC GCSE Computer Science
Programming language translators
Presentation transcript:

OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code to object code; d. describe the difference between interpretation and compilation; e. describe the purpose of intermediate code in a virtual machine; f. describe what happens during lexical analysis; g. describe what happens during syntax analysis, explaining how errors are handled; h. explain the code generation phase and optimisation; i. describe the use of library routines

a. describe the need for, and use of, translators to convert source code to object code; OCR A Level F453: The function and purpose of translators

All computer languages fit on a spectrum from 100% human readable but 0% Computer readable at one end (like natural language). To 0% human readable but 100% Computer readable at the other end (like binary). Translators Natural language Binary PythonCAssembly Code High level languages Low level languages OCR A Level F453: The function and purpose of translators

Binary is referred to as a low level language because it is on the lowest end of this spectrum. All other languages are referred to as high level languages because they are higher up the spectrum than binary. Translators Natural language Binary PythonCAssembly Code High level languages Low level languages OCR A Level F453: The function and purpose of translators

Translators take high level languages like Python and convert them into a low level language (binary) so they can be run on a computer. During this process they also detect errors in the source code. Translators Natural language Binary PythonCAssembly Code High level languages Low level languages OCR A Level F453: The function and purpose of translators

Translation process Step 1: Source code is translated in to object code. Step 2: Object code is then linked with library routines and other pieces of object code to create executable code. Step 3: Executable coded is then loaded in to RAM from secondary memory when the program is run. Key words are highlighted in bold above and defined on the next few slides. OCR A Level F453: The function and purpose of translators

Source code Source code is a program written in a high level language by a user. It is easy for people to understand but cannot be run on a computer until it has been translated by the translator. OCR A Level F453: The function and purpose of translators

Object code Object code is the binary code (sometimes called machine code) produced by the translator from the source code. The whole point of the translator is to convert source code into object code. OCR A Level F453: The function and purpose of translators

Executable code Executable code is the complete, finished program (in binary) that the computer can run without any further translation. It is made by linking together all the different pieces of object code necessary to build the program. OCR A Level F453: The function and purpose of translators

Linker The linker combines the object code with library routines and other pieces of object code to create the executable file. OCR A Level F453: The function and purpose of translators

Loader The loader copies the executable code from secondary memory into RAM so that it can be executed. OCR A Level F453: The function and purpose of translators

Library routines Library routines are the functions like random or print or sort that come packaged with the language. They are useful because they save the programmer time, they’ve already been tested so you know they will work and they can be used multiple times in a program. They also make use of other peoples expertise. OCR A Level F453: The function and purpose of translators

d. describe the difference between interpretation and compilation; OCR A Level F453: The function and purpose of translators

Compilers vs Interpreters There are actually two types of translator called Compilers and Interpreters. Each one translates code slightly differently. Compilers - Compilers scan the whole program first then convert the whole file into object code. Interpreters - Interpreters convert the source code into intermediate code first then into object code. Each line of code is interpreted and then execute separately in a sequence. If an error is found in a particular line it will stop the interpretation without translating the next set of the codes. OCR A Level F453: The function and purpose of translators

f. describe what happens during lexical analysis; g. describe what happens during syntax analysis, explaining how errors are handled; h. explain the code generation phase and optimisation; OCR A Level F453: The function and purpose of translators

Compilers Compilers translate code in three phases: Lexical Analysis - During this phase all the comments and white space are stripped out of the program and reserved words ( IF, THEN ELSE ) are replaced by tokens. Syntax Analysis (Parsing) - This phase takes the output of the Lexical Analyser and checks that it matches the rules of the language. For example that each IF has a matching END IF. Code generation (Optimisation) - The output from the Syntax Analysis is optimised by reducing the number of instructions and increasing the processing speed. C and C++ are both examples of compiled languages. OCR A Level F453: The function and purpose of translators

Interpreters Interpreters translate code one line at a time this gives them a number of advantages of compilers including: - Errors are reported as they occur rather than in one big report at the end (as in compilers), this means they are easier to correct. - Interpreters use less memory as only the object code from a single line of source code is held in memory at any one time. - Interpretation can be restarted from any point when an error has been corrected. -Breakpoints can be inserted into the code to halt execution and display the values currently held in variables. Python is an example of an interpreted language. OCR A Level F453: The function and purpose of translators

e. describe the purpose of intermediate code in a virtual machine; OCR A Level F453: The function and purpose of translators

Intermediate code Interpreters create intermediate code. Compilers do not. Source code Object code Source code Object code Intermediate code Compiler Interpreter Compiled in to.. Interpreted in to.. OCR A Level F453: The function and purpose of translators

Intermediate code Code that has been partly translated by an interpreter into code that needs further translation by the interpreter before it can be executed. Intermediate code can run on a larger range of platforms (computers) which improves portability. As it has already been interpreted once it is also error free. The same intermediate code can be created from different high level languages. However intermediate runs more slowly than executable code. OCR A Level F453: The function and purpose of translators

Virtual Machine Usually a virtual machine means a software simulation (emulation) of a physical computer. For example if you were using the Ubuntu operating system and wanted to play a game that was only built to run on Windows XP you could create a virtual machine version of a Windows XP PC and run the game in that. VirtualBox allows ubuntu users to create virtual machines that run other operating systems. OCR A Level F453: The function and purpose of translators

Virtual machines & interpreters Confusingly it is often said that interpreters create intermediate code that runs on a virtual machine. In this case virtual machine refers to a hypothetical, generalised computer capable of running any program it is given. It’s just an annoying way of saying that intermediate code can be run on any platform which improves the portability of the code,. OCR A Level F453: The function and purpose of translators