Anda di halaman 1dari 17

Program

Implementation
Generations of programming languages
Translator programs
Programming errors

Information Technology
5th Form Handout
Contents
1. What is a program ……………………………………………………………………………………………………………………..3
2. Categories of programming language………………………………………………………………………………………….3
3. 1GL……………………………………………………………………………………………………………………………………………..4
4. 2GL……………………………………………………………………………………………………………………………………….…4-5
5. 3GL………………………………………………………………………………………………………………………………………….5-6
6. 4GL…………………………………………………………………………………………………………………………………………….6
7. 5GL…………………………………………………………………………………………………………………………………………….7
8. What are translator programs......................................................................................................8
9. What is a compiler?......................................................................................................................8
10. The steps of programming implementation.................................................................................9
11. Source code creation....................................................................................................................9
12. Compilation..................................................................................................................................9
13. Linking.........................................................................................................................................10
14. Execution....................................................................................................................................10
15. Maintenance..............................................................................................................................10
16. Illustration of a compiler............................................................................................................11
17. What is a “Programming Error”?...............................................................................................12
18. Types of Programming Errors.....................................................................................................12
19. The Syntax Error....................................................................................................................12-13
20. Logic Error..................................................................................................................................13
21. Runtime Error………………………………………………………………………………………………………………………….13
22. Error Finding and Recognition....................................................................................................14
23. Debugging……………………………………………………………………………………………………………………………….14
24. Testing…………………………………………………………………………………………………………………………………….15
25. Test Cases...................................................................................................................................15
26. Dry Run Testing..........................................................................................................................15
27. Activity.......................................................................................................................................16
28. Bibliography…………………………………………………………………………………………………………………………….17

2|Page
What is a program?
A computer program is a set of instructions that tell a computer what to do and how to perform a task.

Programming languages

 Programming languages, like human languages, consist of a grammar and a set of rules that
govern how elements of the grammar combine to form instructions.
 The set of rules is called the syntax and must be strictly followed for programming instructions
to be valid.

Categories of programming language


Low-Level Language – These languages are machine dependent. That is, the code written can
only be understood by the particular computer or processor that was used to write the code.
Example:
o First generation language
o Second generation language

High-Level Language – These languages are machine independent. That is, programs written on
one computer can generally be used on another similar computer. They also use keywords
similar to English and are easier to write.
Example:
o Third generation language
o Fourth generation language
o Fifth generation language

3|Page
First Generation Languages (1GL)
First generation languages which is also called Machine Language, consists of strings made up of 1s
and 0s. Each machine language instruction is made up of two parts, the operation code and the
operand. The operation code is the operation to be performed such as addition or multiplication 2 and
the operand is the data or memory storage area on which the operation is to be performed.

Example:
11011101 1011011

01001100 1011100

11011100 1011011

Advantages of 1GL

 Fastest to execute because it is already in the language that the computer understands.
 Uses the processor and memory more efficiently

Disadvantages of 1GL

 Difficult to decipher
 Machine dependent
 Time consuming/ tedious to write

Second Generation Languages 2GL


Second generation languages, also known as Assembly Language is written using mnemonic codes.
That is, short codes that suggest their meaning. These codes represent operations, addresses that relate
to main memory and storage registers of the computer. Typical codes might be: LDA, STO, ADD, NOP
etc.

Example: LDA A, 20 {load accumulator A with the value 20}

ADD A, 10 {add the value 10 to accumulator A}

STO B, A {store contents of accumulator A into storage register B}

NOP {No operation (stop here)}

4|Page
Advantages of 2GL

 Easier to write than machine language

Disadvantages of 2GL

 Machine dependent
 Requires translation

Third generation Languages 3GL


Third generation languages or High Level Languages have a grammar and syntax that closely resemble
human languages and mathematical notations.

Language Example

Pascal PROGRAM Addition (Input, Output);

Designed to be used in teaching programming and Var


in business programs. Num1, Num2, Sum : Integer;
BEGIN
Pascal was developed by Niklaus Wirth, a Swiss READLN (Num1, Num2);
computer scientist in 1970 and is named after Sum := Num1 + Num2;
Blaise Pascal, the 17th-century mathematician who END.
invented the mechanical calculator.

BASIC – Beginner’s All-purpose Symbolic Please Research


Instruction Code

Designed for beginners to use

C – Developed by Bell Laboratories in the USA Please Research


(Now AT&T)

FORTRAN – FORmulator TRANslator Please Research

Designed for use by engineers and scientists for


complex mathematical calculations

COBOL – COmmon Business Oriented Language Please Research

5|Page
Advantages of 3GL

 It uses English words and symbols, and is therefore even easier to write.
 It is machine independent.

Disadvantages of 3GL

 Execution is slower than low level languages


 Requires translation
 May take up more storage, in the case of a compiled program.

Fourth Generation Languages 4GL


Fourth Generation Programming Languages use statements similar to those used in human language.

Examples:

 Database query languages, e.g. SQL (Structured Query Language)


 Report generators, e.g. Oracle Report
 GUI creators, e.g. Visual Basic

SQL code:

USE STOCKLIST

SELECT ALL Items

WHERE Price >$10.00

6|Page
Fifth Generation Programming Languages 5GL
A Fifth Generation Language is programming using a visual or graphical development interface to create
source languages that are usually compiled with a 4GL language compiler. 5GLs are designed to build
specific programs that help the computer solve specific problems. They are essentially 4GLs with a
knowledge base. 5GLs are often used in Artificial Intelligence (AI)

Examples:

 OPS5 (Official Production System)


 Prolog (Logical programming)
 Mercury

7|Page
What is a Translator program?
A translator program is a software that converts source code into an object code.

Examples:

Assembler
Interpreter
Compiler

What is a “Compiler”?

A compiler is a translator program that translates high level programming languages to machine
language. The compiler converts the entire source code to an object code which is saved as a separate
copy from the source code. Compilers are used on languages such as C, C++ and Pascal.

What is an Interpreter?
An Interpreter is a translator program that converts source code to object line by line. The object code
created is not stored, hence the need for constant translation. Interpreters are used on languages such
as JavaScript and BASIC.

What is an Assembler?
An Assembler is a translator program that converts assembly language/code to an object code/machine
language.

8|Page
The Steps of Programming Implementation

There are several steps that must be completed before a program can be put in use by a user.

1. Source Code Writing

2. Compilation

3. Linking

4. Execution

After successful execution of a program, the user is able to use the program to complete the task(s) it
was created for. However, program implementation also has a last phase which takes place over the
lifetime use of the program. This phase is called:

5. Maintenance

1. Source Code Creation

Before a program can be ran or placed into production, it must be written or planned. The goal or
outcome of the program must be known and the written step by step procedures to achieve the goal
must be documented. This can be done by writing the steps on paper.

The procedures must then be converted into the syntax of a suitable programming language. This
“typed up” version of the code or procedures is known as the SOURCE CODE.

2. Compilation

In this phase, the compiler scans the source code for syntax errors. If there is no error, the code is either
made into an executable file. The end result of this phase is called object code.

The executable file is the source code converted to its machine language equivalent.

Note: Sometimes linking has to take place before the object code is created.

9|Page
3. Linking

Linking is a process that takes place when more than one object code is needed in order to create an
executable code.

The linker is responsible for this task. It creates a link among object codes after the completion of the
compilation phase.

Errors are sometimes received at this stage. These may be:

Syntactical errors – where rules of the language are disobeyed and

Linking errors – files are not found.

4. Execution

In the execution phase, the program is seen in a console (e.g. DOS Window) or as an application.
Instructions written in the program are carried out by the operating system.

At this stage, errors such as logic and run time errors may be found.

Run Time Error: Fault within the program that may cause the program to crash (malfunction).

Logic Errors: Errors in the output received from the program due to errors in the sequence of
calculations or lines of code.

5. Maintenance

A program or application sometimes requires maintenance after it is placed into production (in use). In
this phase, sections (modules) in the program may be deleted, corrected or added in order to please the
users’ needs. This is a continuous process due to the fact that requirements change.

10 | P a g e
Illustration of a compiler

11 | P a g e
What is a “Programming Error”?

A programming error is a fault that occurs during program compilation and or execution. These errors
either cause programs to crash (stop) or produce the incorrect result(s).

Types of Programming Errors

There are three main types of programming errors:

 Syntax Errors

 Logic Errors and

 Run - Time Errors

The Syntax Error

Syntax, according to Dictionary.com, is “the grammatical rules and structural patterns governing the
ordered use of appropriate words and symbols for issuing commands, writing code, etc., in a particular
software application or programming language”

In shorter terms, syntax can be defined as the rules of a programming language which must be obeyed
in order to have a successfully ran program.

Syntax errors are the most common errors in programming and are mostly caused by simple mistakes.

Possible causes of syntax errors:

 In Pascal, failure to end each line of code with a semicolon will result in syntax errors.

 Misspelt variable names within the program.

 Missing keywords

 No declaration of variables

12 | P a g e
E.g.

Writeln (‘Enter your name)

The above line of code will result in two syntax errors.

1. The single quotation mark is missing from the on-screen prompt statement.

2. The semicolon at the end of the print statement is missing.

Logic Error

If something is logical then it is considered to make sense.

Logic errors occur when simple errors are made by a programmer; the flow or sequence of the program
leads to incorrect results.

Most logic errors occur in mathematical operations where incorrect symbols are used in calculations.

E.g. The following is a line from a Pascal program which is to calculate the sum of 3 numbers.

Sum := (num1*num2+num3);

Note: There is no syntax error in the line of code. However, the sum of three numbers is calculated by
adding each number. In the example above, the multiplication sign was used instead of the plus sign.

Runtime Error

As the name suggests, runtime errors occur while a program is being executed. These error s are
sometimes cause by the input received from the user, lack of memory space on the computer or a
popular calculation of trying to divide a number by zero. These errors are the most difficult errors to
trace because sometimes, the exact cause may not be visible.

E.g. Value:=30/0; OR

int age = “name” An integer variable can only store integer values and not data of other data-
types.

13 | P a g e
Error Finding and Recognition

There are two ways in which a programmer can locate errors within his or her programs.

These are by using:

1. Debugging Techniques

2. Testing Techniques

Debugging

Debugging a program is a three step process.

1. Detection / Error Locating

2. Diagnosis

3. Correction

Detection deals with the process of finding where the errors are located within the source code of the
program; diagnosis tries to determine the cause of the error. After these two steps are completed,
correction can take place.

Several tools and techniques can be used to carry out the debugging process.

 Debuggers – tools used to assist programmers in locating errors in a program.

 Traces – Printout of the step by step flow of the program.

 Variable Checks – Displays the value of variables at different points within the program.

 Step Mode – The program is executed line by line until the error occurs.

14 | P a g e
Testing

Testing is the process of using data within a program to ascertain whether or not the correct result is
received.

This technique uses “test data” or “test cases” which are entered into the program while it is being
executed.

Test Cases

Test cases are documents that are used to store information such as the input data, expected results of
the program, the actual results received after entering the data and necessary comments.

Test case/ data must be written to test all the modules (sections) of a program to ensure that the
correct output is received at all times.

Dry Run Testing

“Dry Run” is the term used to describe the checking of a program for errors without the use of a
computer or compiler.

Dry run testing is a technique used by many programmers. This technique involves the use of trace
tables, algorithms and pseudo-codes. The programmer “runs” through the program, jotting the results
down on paper. This is done before any coding starts (with a programming language).

NOTE:

The difference between testing and debugging is that testing uses test cases to find out if errors exist
while debugging tries to locate errors which exist and work on correcting such errors.

15 | P a g e
Activity

a. The following Pascal code contains errors. Circle all the errors found and place them in their
correct categories (syntax, logic or runtime errors) in the table below.

Hint: There are seven errors.

Program AreaOfSquare

Uses wincrt;

Var Area, side: real;

Begin

Num:= 0 ;

Writeln (Enter the value of the side of the square: );

Readln (side);

Area := side+side/Num;

Writeln (‘The area of the square is: ‘, area);

End

Error Reason Correction Category

b. Given the test data below, what is the actual result and comment for the program above?

Input: 5 Expected Result: 25 Actual Result: _________ Pass/ Fail: _______

16 | P a g e
Bibliography

Gay, G., Blades, R (2009). Information Technology for CSEC. Oxford.

http://www.Dictionary.com

Birbal, R., Taylor, M (2010). Log on to IT for CSEC

King,G, (2010). Programming Made Simple for CSEC

17 | P a g e

Anda mungkin juga menyukai