Fifth Chapter Lesson-2 Translator Programs (Assembler, Compiler, Interpreter).

At the end of this lesson-

  • 1.You will be able to explain translator program.
  • 2.You will be able to describe Assembler and it’s functions.
  • 3.You will be able to describe compiler and it’s function, advantages and disadvantages.
  • 4.You will be able to describe interpreter and it’s function, advantages and disadvantages.
  • 5. You will be able to differentiate interpreter over compiler.

 

Translator Program: The program that converts source program into object program is called translator program. A program written in high-level language is called as source program and a program written in machine language is called as object program. 

A translator takes a program written in source language as input and converts it into a program in target language as output. It also detects and reports the error during translation by providing diagnostic messages wherever the programmer violates specification of the high-level language program.

The different types of translator are as follows:

  • 1. Assembler
  • 2. Compiler
  • 3. Interpreter

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 operation codes to machine language equivalents. 
  • 2. Convert symbolic operands to machine addresses. 
  • 3. Build machine instructions.
  • 4. Convert data constants to internal representations.
  • 5. If there is any error in program, notify with error message.  

 

Compiler: Compiler is a translator program which is used to convert programs in high-level language to low-level language. It translates the entire program and also reports the errors in source program encountered during the translation. How it works- 

  • 1.It analyses all of the language statements for its correctness. If incorrect, throws an error.
  • 2.If no error, the compiler will convert source code to machine code.
  • 3.It links different code files into a runnable program(know as exe). 
  • 4.Run the Program

 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. It takes large amount of time to analyze the source code but the overall execution time is comparatively faster.
  • 2.Generates output program which can be run independently from the original program.

Disadvantages of Compiler:

  • 1.Compiler displays all errors and warning at the compilation time. Therefore, you can’t run the program without fixing errors. 
  • 2.It generates the error message only after scanning the whole program. Hence debugging is comparatively hard. 
  • 3. Generates intermediate object code which further requires linking, hence requires more memory.

 

Interpreter: Interpreter is a translator program which is used to convert programs in high-level language to low-level language. 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.

Advantages of Interpreter:

  • 1.Interpreters are easier to use, especially for beginners.
  • 2.No intermediate object code is generated, hence are memory efficient.
  • 3.Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy.

Disadvantages of Interpreter:

  • 1.It takes less amount of time to analyze the source code but the overall execution time is slower.
  • 2. Do not generate output program. So they evaluate the source program at every time during execution. 

 

 

The difference between an interpreter and a compiler is given below:

CompilerInterpreter
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:

 

Multiple Choice Questions:

 


Written by,

Leave a Reply

Your email address will not be published. Required fields are marked *