5.1.3 COMPILER, INTERPRETER AND ASSEMBLER (LANGUAGE TRANSLATOR) - Computer Notes | Computer Notes for 11 and 12 | PLK Computer Sir

Breaking

Home Top Ad

Post Top Ad

Responsive Ads Here

5.1.3 COMPILER, INTERPRETER AND ASSEMBLER (LANGUAGE TRANSLATOR)

 5.1.3 COMPILER, INTERPRETER AND ASSEMBLER (LANGUAGE TRANSLATOR)

A language translator is a special type of system software that converts a program written in any programming language (except machine language) into machine language program. It is also known as a language processor. A program code written using any programming language is called source code. A program code obtained after converting source code by using language translator is called object code or machine code. Mainly, there are types of language translators: assembler, compiler and interpreter.


1. Assembler

Assembler is defined as a language translator which translates assembly language programs into machine language programs. As computers understand only machine language, assembly language programs must be translated into machine language programs before execution. Otherwise, computer does not understand the codes. The original assembly language program codes are known as source codes and after translation, the final machine language program codes are known as object codes. 


2. Interpreter

An interpreter is a language translator which translates a high level language program into machine language program one instruction at a time. Unlike a compiler, it translates one statement of a program, executes the statement immediately and moves to the next statement. When an error is encountered in the program, the process of translation is halted and an error message is displayed. Programming languages such as BASIC, LISP etc use interpreters. 


3. Compiler

A compiler is a language translator which translates a high level languages program into machine language program. The original code of high level language is called source code and after translation, the final machine language program code is known as object code. While translating the program, it checks the syntax that means grammar of the source code of a high level language program and translates it into machine language program code at single attempt. If there is a syntax error on source code then the compiler produces syntax errors and causes of the errors. The source code file must be free from syntax errors for the complete compilation process. Compiler is more efficient and faster than the interpreter.

For each high level language, a separate compiler is required. For example: a C language compiler cannot translate a program written in JAVA programming languages. Programming languages such as C, C++, C# and Visual Basic, etc. use compiler. Java has both a compiler and interpreter.


Difference between compiler and interpreter

Compiler

Interpreter

i) It translates a high level language program into a machine language program at a single attempt.

(i) It translates a high level language program into a machine languages program by one instruction at a time.

(ii) It finds the syntax errors after compiling the whole program.

(ii) It finds the syntax errors after translating a line of the program at a time.

(iii) It is difficult to trace errors and causes of the errors.

(iii)  It is easy to trace errors and causes of the errors.

(iv) The compiling process is faster than the interpreter.

(iv) The interpreting process is slower than the compiler.

(v) It is more efficient than an interpreter.

(v) It is less efficient than a compiler.

(vi) It creates the object code.

(vi) It doesn’t create object code.

(vii) Examples: C,C++, Visual Basic etc.

(vii) Examples: BASIC, LISP etc.

 

5.1.4 SYNTAX, SEMANTIC AND RUNTIME ERRORS

Syntax of a programming language defines the grammatical rules to construct an instruction in a program. Moreover, it also defines the alphabets, numbers, operators, expression and structure of an instruction. This is the fundamental rule that must be followed by a programmer. Otherwise, the language does not understand the codes of a program. If it is syntactically correct, then the source codes are translated into machine code.



A semantic of a programming language defines the logical meaning of an instruction. Compiler does not identify the semantic of a program. So, it is difficult to identify the semantics of a program. To identify the semantics of a program, a programmer might take some sample data to verify the outputs. We can consider the following English statement to know the idea of syntax and semantics.

 

Examples

Description

I eat rice.

Syntactically and semantically correct

I eat chairs.

Syntactically correct but semantically incorrect

I eats chairs.

Syntactically and semantically incorrect 



 

POINTS TO REMEMBER (PTR)

Syntax defines grammatical rules for the language whereas semantic defines the logical meaning of any programming language. 



A program is never 100% correct throughout its life span. But we assume that a program should be almost 100% correct, otherwise a program does not fulfil the actual requirements of users. There might be some mistake due to the violation of rules of programming language, called errors or bugs. The process of finding bugs is called debugging. Mainly, there are three types of errors in the program: syntax errors, logical (semantics) errors and runtime errors.



Syntax Error 

A syntax error has occurred due to the violation of syntax of a programming language. The key words (reserved words by the programming language) and the structure of the instructions must be in the correct form. A syntax error is easy to debug because the compiler itself detects syntax error and describes the causes of the errors. So, a programmer does not need to trace the errors in a program. 



Logical Error 

A logical error occurs due to the violation of semantics of a programming language. It is also called semantics errors. Meaningless instructions cause the logical errors so the wrong logic must be carefully removed from the program. A compiler does not detect the logical errors, therefore they are very difficult to find out. The actual output does not come as per the given data therefore, sample data is supplied to the program to examine the logic errors. 



Runtime Error

A runtime error occurs during the running time of the software. It occurred due to the problem of system or mishandling of the software. Run time error might occur anytime while running a program. So, a good programmer must handle the errors using different error handling mechanisms during software development time.



Ch 5 Assignment-2

1.                 List any three language translators.

2.                 List any three interpreted programming languages.

3.                 List any three compiler-based programming languages.

4.                 Compare between compiler and interpreter. 

5.                 Draw figures of assembler, interpreter and compiler. 

6.                 Compare syntax and semantics of a programming language.

7.                 Give an example of run time error. 

 

No comments:

Post a Comment

Post Bottom Ad

Responsive Ads Here

Pages