34
Programming Programming Translators Translators

Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Embed Size (px)

Citation preview

Page 1: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

ProgrammingProgramming

TranslatorsTranslators

Page 2: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Learning ObjectivesLearning Objectives

Explain: What translators do The process of source-object code The three major error types which will need to be tested The concept of developing a test plan. Black box testing White box testing The concepts of Alpha tests and Beta tests Translator diagnostics Cross referencing Program traces Variable dumps Dry runs (desk checks)

Page 3: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

• The general term used to describe all the programs, routines or procedures that run on a computer.

• Makes a computer do something and are written to run on the hardware.

•Computer instructions or data.

•Any instructions that can be stored electronically are software.

SoftwareSoftware

Page 4: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

SoftwareSoftware

Computer instructions or data. Computer instructions or data.

Makes a computer do something and are Makes a computer do something and are written to run on the hardware.written to run on the hardware.

Hardware

Software

Page 5: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Hardware

High Level Languagese.g. Pascal, Visual Basic, C, Fortran

Machine Code

Software is usually written in a high level Software is usually written in a high level language which is fairly similar to our own language which is fairly similar to our own spoken languages.spoken languages. This makes it easier for us humans to use.This makes it easier for us humans to use.

However, computers only understand However, computers only understand machine code which is in binary form (1s machine code which is in binary form (1s and 0s).and 0s).

Page 6: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Translators High Level Languages

Machine Code

SourceCode

ObjectCode

TranslatorsTranslators

Translate high level languages (the Translate high level languages (the translator’s source code) into machine translator’s source code) into machine code (the translator’s object code) which code (the translator’s object code) which can be executed by a computer.can be executed by a computer.

Code written in a high level

language.

Code in executable

form.

Page 7: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

There are three types program error (bug)

Page 8: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

1. Syntax errors1. Syntax errors

Errors in a program that break the Errors in a program that break the grammar rulesgrammar rules of the language of the language being being used.used. e.g. e.g.

PLINTPLINT instead of instead of PRINTPRINT

3*(2+A) = X3*(2+A) = X instead of instead of X = 3*(2+A) X = 3*(2+A)

Simplest errors to solve as the translator Simplest errors to solve as the translator will find these errors before the program is will find these errors before the program is run.run.

Page 9: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Translator diagnosticsTranslator diagnostics

The translator looks up each word from a program in The translator looks up each word from a program in a dictionary. a dictionary. The dictionary tells the translator program what the rules The dictionary tells the translator program what the rules

are for that particular word. are for that particular word.

A wrongly typed word will not appear in the A wrongly typed word will not appear in the dictionary. dictionary. If rules governing how it should be used have not If rules governing how it should be used have not been followed properly, the translator will know that been followed properly, the translator will know that there is something wrong. there is something wrong. Either way, the translator program knows that a mistake Either way, the translator program knows that a mistake

has been made, it knows where the mistake is and, often, has been made, it knows where the mistake is and, often, it also knows what mistake has been made. it also knows what mistake has been made.

Page 10: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Translator diagnosticsTranslator diagnostics

Messages detailing syntax errors sent to Messages detailing syntax errors sent to the programmer and usually giving hints the programmer and usually giving hints as to what to do.as to what to do.

Page 11: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

2. Logic errors 2. Logic errors (also known as run-time (also known as run-time errors if found when a program is run)errors if found when a program is run)

A mistake in the way the program solution A mistake in the way the program solution has been designed.has been designed. e.g.e.g.

An instruction in a program may tell the computer to An instruction in a program may tell the computer to jump to the wrong part of the program.jump to the wrong part of the program.

Total_number = Previous_total – New_numberTotal_number = Previous_total – New_number

Known as logic errors if found whilst not running a Known as logic errors if found whilst not running a program and using white box testing program and using white box testing – see later – see later slide 24..

Known as run-time errors if found when actually Known as run-time errors if found when actually running a program running a program (black box testing – see slide (black box testing – see slide 17))..

Page 12: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

3. Arithmetic Errors 3. Arithmetic Errors (also known run-time errors (also known run-time errors if found when a program is run)if found when a program is run)

Inappropriate use of arithmetic. Inappropriate use of arithmetic. E.g. dividing by zeroE.g. dividing by zero

Known as arithmetic errors if found whilst Known as arithmetic errors if found whilst not running a program and using white box not running a program and using white box testing testing – see later – see later slide 24..

Known as run-time errors if found when Known as run-time errors if found when actually running a program actually running a program (black box testing – (black box testing –

see slide see slide 17))..

Page 13: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

The last two errors (logic and arithmetic) The last two errors (logic and arithmetic) will not be found by the translator, so the will not be found by the translator, so the program will run but won’t work properly.program will run but won’t work properly.

Known collectively as Known collectively as run-time errorsrun-time errors if found if found when actually running a program (black box when actually running a program (black box testing – see slide testing – see slide 17).).

Page 14: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Program DevelopmentProgram Development

1.1. Testing:Testing:Are there any errors (bugs)?Are there any errors (bugs)?

2.2. Debugging:Debugging:Where is the error (bug) and what is causing Where is the error (bug) and what is causing it? it?

Solve the error (bug).Solve the error (bug).

Page 15: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Test Plan

A schedule drawn up which contains a test for every type of input that could be made and methods of testing that the program actually does what it was meant to do.

Page 16: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Alpha TestingAlpha Testing

Performed by the programmers involved in Performed by the programmers involved in writing the program.writing the program.

Focus on error free processing.Focus on error free processing.

Page 17: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Black box testing

Use of different input values to determine Use of different input values to determine whether the program can cope with them. whether the program can cope with them. These values should include These values should include

Different types of input e.g.Different types of input e.g. Typical valuesTypical values Borderline values Borderline values Unacceptable valuesUnacceptable values

Cannot see into the box (program) all you Cannot see into the box (program) all you see is what comes out at the end. see is what comes out at the end.

Page 18: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Example 1 of Black Box TestingExample 1 of Black Box Testing

A program which uses marks out of 100 A program which uses marks out of 100 from a math's examination as input.from a math's examination as input. Typical data like: 27, 73.., Typical data like: 27, 73.., Borderline data: 0 and 100Borderline data: 0 and 100 Unacceptable data like: –34, 123, 16.345 Unacceptable data like: –34, 123, 16.345

Page 19: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Example 2 of Black Box TestingExample 2 of Black Box Testing

A program to work out the mean of three A program to work out the mean of three numbers.numbers. 1, 2, 3 Will integers give an integer answer?1, 2, 3 Will integers give an integer answer? 1, 2, 4 Can the software cope with a recurring 1, 2, 4 Can the software cope with a recurring

decimal answer?decimal answer?(Note that “1, 2, 4 to test a different set of integers” would (Note that “1, 2, 4 to test a different set of integers” would not get a mark because the reason for the test is not not get a mark because the reason for the test is not different)different)

1, 2.5, 3 Can the program handle decimal inputs?1, 2.5, 3 Can the program handle decimal inputs? 1, 2½, 3 Are fractions allowed?1, 2½, 3 Are fractions allowed? -1, -2, -3 Can negative numbers be handled?-1, -2, -3 Can negative numbers be handled? 1, 2 What happens when only two values are input?1, 2 What happens when only two values are input?

Page 20: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Debugging ToolsDebugging Tools

Debugging tools to allow programmers to Debugging tools to allow programmers to investigate conditions where errors occur.investigate conditions where errors occur.

The following slides describe some The following slides describe some debugging tools.debugging tools.

Page 21: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Cross-referencingCross-referencing

This software checks the program that has This software checks the program that has been written and finds places where been written and finds places where particular variables have been used. particular variables have been used.

This lets the programmer check to make This lets the programmer check to make sure that the same variable has not been sure that the same variable has not been used twice for different things.used twice for different things.

Page 22: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Tracing variable values / Variable Tracing variable values / Variable Watching / SteppingWatching / Stepping

Where the program is run and the values Where the program is run and the values of all the relevant variables are printed out, of all the relevant variables are printed out, as are the individual instructions, as each as are the individual instructions, as each instruction is executed. instruction is executed.

In this way, the values can be checked to In this way, the values can be checked to see where they suddenly change or take see where they suddenly change or take on an unexpected value.on an unexpected value.

Page 23: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Break Points / Variable dumps / Break Points / Variable dumps / Variable WatchesVariable Watches

At specified parts of the program, the values of At specified parts of the program, the values of all the variables are displayed to enable the user all the variables are displayed to enable the user to compare them with the expected results.to compare them with the expected results.

This enables the programmer to see where This enables the programmer to see where sudden, unexpected changes occur.sudden, unexpected changes occur. Often used in conjunction with tOften used in conjunction with tracing variable racing variable

values / Variable Watching / Stepping values / Variable Watching / Stepping i.e. set breakpoints and then use tracing from these points as i.e. set breakpoints and then use tracing from these points as required.required.

Particularly useful for long programs where errors are Particularly useful for long programs where errors are believed to be only in certain parts of the code.believed to be only in certain parts of the code.

Page 24: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

White Box Testing / Dry Runs / White Box Testing / Dry Runs / Desk CheckingDesk Checking

The user works through every logical path of the The user works through every logical path of the program instructions manually, keeping track of the program instructions manually, keeping track of the values of the variables. values of the variables.

Basically manual tracing or variable watches.Basically manual tracing or variable watches.

Most computer programs require a very large number of Most computer programs require a very large number of instructions to be carried out, so it is usual to only dry run instructions to be carried out, so it is usual to only dry run small segments of code that the programmer suspects of small segments of code that the programmer suspects of harboring an error.harboring an error.Testing knowing the code.Testing knowing the code.Testing the structure and logic of all the algorithms within Testing the structure and logic of all the algorithms within the code.the code.

Known as “white box” as testing is done by looking at the code Known as “white box” as testing is done by looking at the code so the program is like a transparent box.so the program is like a transparent box.

Page 25: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Beta TestingBeta Testing

Testing carried out by the users of the Testing carried out by the users of the programprogram.. Eventually, the company will want ordinary Eventually, the company will want ordinary

users to test the program because they are users to test the program because they are likely to find errors that the programmers did likely to find errors that the programmers did not find.not find.

Focus on usability, functionality, and Focus on usability, functionality, and performance.performance.

Page 26: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

PlenaryPlenary

What is:What is: Source code?Source code?

Code written in hll.Code written in hll. Object code?Object code?

Code in executable form Code in executable form Machine code?Machine code?

Code in binary form. Code in binary form.

What is the process which connects source What is the process which connects source and object code?and object code?

A translator turns the source code into the object A translator turns the source code into the object code. code.

Page 27: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

PlenaryPlenary

Explain how the translator program Explain how the translator program prepares the programmer’s code into a prepares the programmer’s code into a program that the machine can run.program that the machine can run.

Translator program turns source into object.Translator program turns source into object. Spots some of the errors in the source code.Spots some of the errors in the source code.

Wrong (reserved) wordsWrong (reserved) words

Wrong syntax in instruction constructionWrong syntax in instruction construction Reports errors to user.Reports errors to user.

Page 28: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

PlenaryPlenary

State the meaning of the following types of State the meaning of the following types of testing.testing.

White box testing.White box testing.Testing all possible routes through the program Testing all possible routes through the program logic/Testing knowing the code/Test the algorithm. Note: logic/Testing knowing the code/Test the algorithm. Note: not dry run on its own not dry run on its own

Black box testing.Black box testing.Test that the outcome is as expected for a given Test that the outcome is as expected for a given input/Testing not knowing the codeinput/Testing not knowing the code

Alpha testing.Alpha testing.Testing by programmer/in-houseTesting by programmer/in-house

Beta testing. Beta testing. Testing by public/end users/potential users/unconnected Testing by public/end users/potential users/unconnected with writingwith writing

Page 29: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

PlenaryPlenary

State State threethree types of program error and give an types of program error and give an example of each. example of each.

Syntax errorSyntax errorMistyping a reserved word, e.g. typing plint instead of printMistyping a reserved word, e.g. typing plint instead of print

Logic errorLogic errorA jump instruction that tells the computer to jump to the A jump instruction that tells the computer to jump to the wrong placewrong place

Arithmetic errorArithmetic errorInappropriate use of arithmetic.Inappropriate use of arithmetic. Dividing by zeroDividing by zero

Page 30: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

PlenaryPlenary

Describe the techniques that can be used Describe the techniques that can be used to help debug a program.to help debug a program.

Page 31: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

White Box Testing / Dry Runs / White Box Testing / Dry Runs / Desk CheckingDesk Checking

The user works through the program instructions The user works through the program instructions manually, keeping track of the values of the manually, keeping track of the values of the variables. variables. Most computer programs require a very large Most computer programs require a very large number of instructions to be carried out, so it is number of instructions to be carried out, so it is usual to only dry run small segments of code usual to only dry run small segments of code that the programmer suspects of harboring an that the programmer suspects of harboring an error.error.Testing knowing the code.Testing knowing the code.Testing specific algorithms within the code.Testing specific algorithms within the code. Known as “white box” as testing is done by looking at Known as “white box” as testing is done by looking at

the code so the program is like a transparent box.the code so the program is like a transparent box.

Page 32: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Cross-referencingCross-referencing

This software checks the program that has This software checks the program that has been written and finds places where been written and finds places where particular variables have been used. particular variables have been used.

This lets the programmer check to make This lets the programmer check to make sure that the same variable has not been sure that the same variable has not been used twice for different things.used twice for different things.

Page 33: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

TracesTraces

A trace is where the program is run and A trace is where the program is run and the values of all the relevant variables are the values of all the relevant variables are printed out, as are the individual printed out, as are the individual instructions, as each instruction is instructions, as each instruction is executed. executed.

In this way, the values can be checked to In this way, the values can be checked to see where they suddenly change or take see where they suddenly change or take on an unexpected value.on an unexpected value.

Page 34: Programming Translators. Learning Objectives Explain: What translators do The process of source-object code The three major error types which will need

Variable dumpsVariable dumps

At specified parts of the program, the At specified parts of the program, the values of all the variables are displayed to values of all the variables are displayed to enable the user to compare them with the enable the user to compare them with the expected results.expected results.