Presentation is loading. Please wait.

Presentation is loading. Please wait.

WJEC GCSE Computer Science

Similar presentations


Presentation on theme: "WJEC GCSE Computer Science"— Presentation transcript:

1 WJEC GCSE Computer Science
Unit 1 Translators and Errors

2 Objectives Describe and Explain the purpose of translators:
Why translators, compilers, interpreters, and assemblers are needed The types of Programming Error that may occur including: Syntax Run-Time Logical Linking Rounding Truncation

3 Translators The code produced in most languages cannot be understood by a computer until it is translated, in some way, into machine code. Several tools are available to do this and they are collectively referred to as translators. Each translator is a piece of software with the job of making program code understandable to the computer.

4 Assemblers An assembler is a program which coverts the low level assembly programming language into machine code. The assembler does this by converting the one word assembly instructions into an opcode, e.g. converting AND to It also allocates memory to variables, often resulting in an operand.

5 Interpreters Before high level programming languages can be run, code is converted by an interpreter, one line at a time, into machine code, which is then executed by the CPU. A program translated in this way will run slower than if it is compiled, and if the program contains any errors the programmer will not find this out until the interpreter reaches the line containing the error.

6 Compilers A compiler is used when high level programming languages are converted into machine code, ready to be executed by the CPU. If there are any errors in the code, the program will not compile and the programmer will have to remove these errors before trying again.

7 Stages of Compilation For example: Message = “Hello World” print(Message) Would be turned into the following code: 2A 1A 1B Message 1B Lexical analysis Comments and unneeded spaces are removed. Keywords, constants and identifiers are replaced by 'tokens'. A symbol table is created which holds the addresses of variables, labels and subroutines. Keyword Token = 1A 1B ( 1C ) 1D print 1E Identifier Token Message 2A

8 Stages of Compilation Syntax analysis
Tokens are checked to see if they match the spelling and grammar expected, using standard language definitions. If syntax errors are found, error messages are produced.

9 Stages of Compilation Semantic analysis
Variables are checked to ensure that they have been properly declared and used. Variables are checked to ensure that they are of the correct data type, e.g. real values are not being assigned to integers. Operations are checked to ensure that they are legal for the type of variable being used, e.g. you would not try to store the result of a division operation as an integer.

10 Stages of Compilation For example: Message = “Hello World” print(Message) Would be turned into the following code: 2A 1A 1C 1B Message 1B 1D 1E 2A Code generation Machine code is generated. Code optimisation may be employed to make it more efficient/faster/less resource intense. Keyword Token = 1A 1B ( 1C ) 1D print 1E Identifier Token Message 2A

11 Workbook Complete section 7b Q1

12 Programming Errors Programmers are human, so they make mistakes.
They actually make mistakes that fall into different categories. You need to be aware of the following types of error: Syntax Run-time / execution Logical Linking Rounding Truncation

13 Incorrect: IF A ADN B Then
Syntax Error An error that occurs when a command does not follow the expected syntax of the language, e.g. when a keyword is incorrectly spelt. Example Incorrect: IF A ADN B Then Correct: IF A AND B Then

14 Runtime / Execution Error
An error that only occurs when the program is running and is difficult to foresee before a program is compiled and run Examples Program requests more memory when none is available, so the program crashes The program might need a connection to the Internet in order to function, and the Internet is not currently available A fault with a piece of hardware, such as a particular disk drive, might prevent the program from completing its task

15 Logical Error An error that causes a program to output an incorrect answer (that does not necessarily crash the program) Example A program that calculates a percentage multiplies a value by 1000 instead of 100, giving the wrong answer.

16 Linking Error An error that occurs when a programmer calls a function within a program and the correct library has not been linked to that program Example When the square root function is used and the library that calculates the square root has not been linked to the program

17 Rounding Error Rounding is when a number is approximated to nearest whole number/tenth/hundredth, etc. Example 34.5 rounded to the nearest whole number is 35, an error of +0.5

18 Truncation Error Truncating is when a number is approximated to a whole number/tenth/hundredth, etc. nearer zero Example 34.9 truncated to whole number is 34, an error of -0.9

19 Workbook Complete section 7b Q2-3

20 Have you completed today’s work and any previous sections?

21 Programming Constructs
Complete section 7c Q1-5


Download ppt "WJEC GCSE Computer Science"

Similar presentations


Ads by Google