What is an interpreter, differentiate between compiler and interpreter?

by jack| Views: 4843

What is an interpreter, differentiate between compiler and interpreter?

Tags:  Oops Interview

Answers (1)
manish Said..

Compiler: we usually prefer to write computer programs in languages we understand rather than in machine language, but the processor can only understand machine language. So we need a way of converting our instructions (source code) into machine language. This is done by an compiler. A compiler is a special program that processes statements written in a particular programming language and converts them into machine language, a "binary program" or "code," that a computer processor uses.

Examples of compilers are Visual Basic, C, C++, C#, Fortran, Cobol, Ada, Pascal and so on.

Interpreter: an interpreter reads the source code one instruction or line at a time, converts this line into machine code and executes it. The machine code is then discarded and the next line is read. The advantage of this is it's simple and you can interrupt it while it is running, change the program and either continue or start again. The disadvantage is that every line has to be translated every time it is executed, even if it is executed many times as the program runs. Because of this interpreters tend to be slow.

Examples of interpreters are Basic on older home computers, and script interpreters such as JavaScript, and languages such as Lisp and Forth.

Assembler: sometimes we see a third type of translation program as an assembler. This is like a compiler, but works at a much lower level, where one source code line usually translates directly into one machine code instruction. Assemblers are normally used only by people who want to squeeze the last bit of performance out of a processor by working at machine code level.

Register or Login to Post Your Opinion/Answer