Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 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

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

3 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: 3.3.2 The function and purpose of translators

4 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: 3.3.2 The function and purpose of translators

5 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: 3.3.2 The function and purpose of translators

6 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: 3.3.2 The function and purpose of translators

7 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: 3.3.2 The function and purpose of translators

8 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: 3.3.2 The function and purpose of translators

9 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: 3.3.2 The function and purpose of translators

10 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: 3.3.2 The function and purpose of translators

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

12 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: 3.3.2 The function and purpose of translators

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

14 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: 3.3.2 The function and purpose of translators

15 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: 3.3.2 The function and purpose of translators

16 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: 3.3.2 The function and purpose of translators

17 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: 3.3.2 The function and purpose of translators

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

19 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: 3.3.2 The function and purpose of translators

20 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: 3.3.2 The function and purpose of translators

21 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: 3.3.2 The function and purpose of translators

22 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: 3.3.2 The function and purpose of translators


Download ppt "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."

Similar presentations


Ads by Google