At the end of this lesson-
1. You will be able to explain translator program.
2. You will be able to describe compiler and it’s function, advantages and disadvantages.
3. You will be able to describe interpreter and it’s function, advantages and disadvantages.
4. You will be able to differentiate interpreter over compiler.
5. You will be able to describe Assembler and it’s functions.
Go for Bangla Version
Translator Program:
Any machine including computer can understand only 0 and 1. This means that only instructions or programs written in machine language can be understood directly but instructions or programs written in other programming languages cannot be understood directly by the machine. Today programmers write programs or instruct machines using a variety of high-level programming languages. For this, it requires translation of programs written in high-level programming languages to make them machine-understandable. The program or software that does this translation work is called the translator program or translator software. Translator software is one kind of system software or language processor. There are separate translator programs for each programming language.
The program that converts source program into object program is called translator program.
A program written in high-level language is called source program and a program written in machine language is called object program.
A translator program takes in source program as input and converts it into object program as output. It also detects and reports the error during translation by providing diagnostic messages wherever the programmer violates syntax of the high-level language.
The different types of translator are as follows:
1. Compiler
2. Interpreter
3. Assembler
Compiler:
A compiler is a type of translator program that Scans the entire program written in a high-level language and translates it as a whole into machine code.. That is, the source program into an object program.
The compiler completes the task of translation in two steps –
In the first step, the compiler reads the source program and converts into the objects programs. In this step, if there is a syntax error in the source program, the compiler gives the user an error message to correct it. This error message is called Compiled Time Diagnostic Error Message. Once the program is compiled, there is no need to compile it later.
The second step is to execute the object program to display the results on the basis of input data.
Programming language like C, C++ use compilers.
Functions of the Compiler:
1. Link with the corresponding sub-routine.
2. Convert source program statements into object programs or machine language.
3. If there is any syntax error in the program, make a list of errors during translation.
4. Identify the range of main memory.
A compiler is likely to perform many or all of the following operations: pre-processing, lexical analysis, parsing, semantic analysis, conversion of input programs to an intermediate representation, code optimization and code generation.
Advantages of Compiler:
1. The compiler translates the entire program together, the overall execution time is comparatively faster.
2. The program converted through the compiler is completely converted into machine language.
3. Generates output program which can be run independently from the original program.
4. Once the program is compiled, it is no longer needed to compile.
Disadvantages of Compiler:
1. The compiler displays all the errors of the program at once, so it takes more time to correct the program.
2. Program debugging and testing is slower.
3. As the compiler is a large program, it requires more space in memory to store.
Interpreter:
An interpreter, like a compiler, is a kind of translator program that reads one line of a program written in a high-level language and converts it into mechanical language and executes it, displaying instant results.
The difference with the compiler is that the compiler converts the entire source program into an object program and provides the latest results but the interpreter converts the source program into a line-by-line object program and displays instant results.
Interpreter translates line by line and reports the error once it encountered during the translation process. It directly executes the operations specified in the source program when the input is given by the user. It gives better error diagnostics than a compiler.
Programming language like Python, Ruby use interpreters.
Functions of the Interpreter:
1. Link with the corresponding sub-routine.
2. Convert source program statements into object programs or machine language.
3. If there is any syntax error in the program, make a list of errors during translation.
4. Identify the range of main memory.
Advantages of Interpreter:
1. The biggest advantage of the interpreter is that it is user friendly.
2. It is easy to use to correct and change program errors.
3. The smaller the interpreter, the less space it takes up in memory.
4. It is commonly used in small computers.
Disadvantages of Interpreter:
1. Since the interpreter translates the program line-by-line, it takes more time than the compiler to translate.
2. Programs converted through interpreters are not completely converted into machine or object programs.
3. Translation is required every time the program is executed.
4. Do not generate output program. So they evaluate the source program at every time during execution.
Assembler:
Assembler is a translator program which is used to translate the assembly language code into machine language code.
Functions of assembler:
1. Convert mnemonic codes into equivalent machine code.
2. Convert symbolic operands or address to machine addresses.
3. Keep all instructions and data in main memory.
4. If there is any error in program, notify with error message.
5. Informing the program control after correcting all the errors in the program etc.
The difference between an interpreter and a compiler is given below:
Compiler | Interpreter |
---|---|
Scans the entire program and translates it as a whole into machine code. | Translates program one statement at a time. |
It takes large amount of time to analyze the source code but the overall execution time is comparatively faster. | It takes less amount of time to analyze the source code but the overall execution time is slower. |
Generates intermediate object code which further requires linking, hence requires more memory. | No intermediate object code is generated, hence are memory efficient. |
Compiler displays all errors and warning at the compilation time. Therefore, you can’t run the program without fixing errors. | The interpreter reads a single statement and shows the error if any. You must correct the error to interpret next line. |
It generates the error message only after scanning the whole program. Hence debugging is comparatively hard. | Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy. |
Store machine language as machine code on the disk. | Not saving machine code at all. |
Generates output program which can be run independently from the original program. | Do not generate output program. So they evaluate the source program at every time during execution. |
Programming language like C, C++ use compilers. | Programming language like Python, Ruby use interpreters. |
Lesson Evaluation-
Knowledge Based Questions:
a) What is translator program?
a) What is assembler?
a) What is compiler?
a) What is interpreter?
a) What is source code or program?
a) What is object code or program?
Comprehension Based Questions:
b) ‘As a translator program compiler is more suitable’-explain.
b) ‘It needs to compile the program each time of execution’-explain.
b) In which case interpreter is better than compiler? -explain.
b) Why source program is needed to translate? -explain.
Creative Questions:
Read the stem and answer the questions:
Arafat and Nila are two programmers. Arafat writes programs with the help of various mnemonics. On the other hand, Nila’s written program is closer to human language to see. Programs written by two of them can solve the same problem.
c) Explain the translator program used to translate the program written by Arafat.
d) Which translator program is more convenient for converting the Nila’s written program into an object program? Analyze.
Read the stem and answer the questions:
Rahim and Karim are programmers. They follow two different programming approaches to write programs. Rahim’s program corrects the error after reading the whole program and Karim’s program corrects error of each line separately. Kabbo on the other hand uses different English words to write programs.
d) Which of the following is quicker in executing the programs of Rahim and Karim mentioned in the stem? Give analytical feedback.
Multiple Choice Questions:
1. How many types of translator software?
a) 2 b) 3
c) 4 d) 5
2. What is called a program written in high level language?
a) Object program b) Source program
c) Visual program d) Translator program
3. The advantage of compiler is-
i. Translates the entire program at once
ii. Debugging and testing in the program is faster
ii. If there is error displays it on the monitor
Which one is correct?
a) i & ii b) i & iii
c) ii & iii d) i, ii & iii
4. Which translator program is used for C programming language?
i. Compiler
ii. Interpreter
iii. Assembler
Which one is correct?
a) i & ii b) i & iii
c) ii & iii d) i, ii & iii
5. Differences between a compiler and an interpreter are-
i. In case of program translation
ii. In terms of work speed
iii. In case of error display
Which one is correct?
a) i & ii b) i & iii
c) ii & iii d) i, ii & iii
Written by,
- Mizanur Rahman (Mizan)
- Lecturer in ICT, Shaheed Bir Uttam Lt. Anwar Girls’ College , Dhaka Cantonment
- Founder & Author at www.edupointbd.com
- Software Engineer at mands IT
- Former Lecturer in ICT, Cambrian College, Dhaka
- Contact: 01724351470