View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12921 Members
Join this group to post and comment.
sai krishna
sai krishna • Dec 13, 2007

Difference between compiler and interpreter

I'm looking for the major difference between compiler and interpreter - the terms commonly used in computer programming and computer science. As the title suggests can any one briefly explain me the diff. between compiler and interpreter

Here's what I understand: A compiler is what the name suggests - compiler of the code. A compiler will read through all the code (computer instructions) and then turn it into an executable aka a file that contains machine readable binary code. Since the computer won't have to do much computing to execute a program that has been compiled, the execution will be much faster.

On the other hand, the Interpreter is something that 'interprets' in the real time. That is, the interpreter will go on reading the lines of code one by one and then execute whatever it encounters. A punch card reader would be a great example of an Interpreter where it reads each of the punched lines one by one and then takes action accordingly. An interpreter will mostly execute the high level instructions and therefore an interpreter will be slower in operations than the compiler.

One major difference between a compiler and interpreter is that once a code is compiled and if some changes are required, then the whole code will have to be compiled again. However, in case of an interpreter, the developer can change code at any point in time and it will be executed - without having to spend any time on understanding the change. I look forward to knowing more differences.
Prasad Ajinkya
Prasad Ajinkya • Jan 8, 2008
Hi Sai,

A compiler first takes in the entire program, checks for errors, compiles it and then executes it. Whereas, an interpreter does this line by line, so it takes one line, checks it for errors and then executes it.

Eg of Compiler - Java
Eg of Interpreter - PHP

Hope this clarifies things.

PS - Oh, and sorry for such a late reply 😁 😁
Sunu
Sunu • Jan 17, 2008
sai krishna
Hi CEans


As the title suggests can any one breifly explain me the diff. b\n compiler and interpreter


thanks inadvance.
They are both similar as they achieve similar purposes, but inherently different as to how they achieve that purpose. Compiled code takes programs (source) written in some kind of programming language, and then ultimately translates it into object code or machine language. Compiled code does the work much more efficiently, because it produces a complete machine language program, which can then be executed. The interpreter translates instructions one at a time, and then executes those instructions immediately. The compiler is itself a computer program written usually in some implementation language.
friendster7
friendster7 • Feb 3, 2008
interpretor translate the program line by line and compiler translate the entire program interpretor requires less memory and compiler requires more memory

definition of compiler:


Compiler is a program that translates a computer program written on one computer language to another computer language. A "compiler" is primarily used for programs that translate source code from a high level language to a lower level language (e.g., assembly language or machine language). A program that translates from a low level language to a higher level one is a decompiler. A compiler for a relatively simple language written by one person might be a single, monolithic, piece of software. When the source language is large and complex, and high quality output is required the design may be split into a number of relatively independent phases, or passes. Having separate phases means development can be parceled up into small parts and given to different people. It also becomes much easier to replace a single phase by an improved one, or to insert new phases later.



Interpreter is a program that translates an instruction into a machine language and executes it before proceeding to the next instruction..... A high-level programming language translator that translates and runs the program at the same time. It translates one program statement into machine language, executes it, and then proceeds to the next statement. This differs from regular executable programs that are presented to the computer as binary-coded instructions. Interpreted programs remain in the source language the programmer wrote in, which is human readable text. Interpreted programs run slower than their compiler counterparts. Whereas the compiler translates the entire program before it is run, interpreters translate a line at a time while the program is being run. However, it is very convenient to write an interpreted program, since a single line of code can be tested interactively.
Hey Java is both compiled as well as interpreted.The compiler first compiles the source code and gives a .class file .This is then executed by JVM which is the interpreter.
Now, the compiler is a program which takes our whole source code at once and then converts it into machine code or a code closer to machine code in representation.On the other hand the interpreter takes the code line by line and executes it line by line.
The compiler follows the physical sequence and interpreter follows the logical one.
Features like loops are better compiled but those like switch result better execution if interpreted.
thechamp
thechamp • Feb 28, 2010
can someone illustrate advantages/disadvantages of interpreter over compiler? i mean which one would be preferrable in C++
anzilkasim
anzilkasim • Mar 1, 2010
Compiler and interpretter are both translaters used for converting the source program to computer readable form.
Major difference between compiler and interpretter is that compiler converts the high level language program (source code) to machine readable form as a whole (like C, C++ and Java program -there we write the entire program and then compile and the errors will be shown like 25 errors, 16 errors etc...) while an interpretter converts the HLL to ML line by line (like VB - there we write a statement like if (condition) and if we omit the 'then' statement and press enter - we cant move to second line since the interpretter will show an error and after typing 'then' only we can move to the next line.

Anzil Kasim

optimystix
optimystix • Mar 1, 2010
kidakaka gave the most precise answer to the question. U can always check wikipedia for more information.

theoretically, in most cases, its the compiler that is better. it checks the entire source code for errors and if error free will execute it. Interpreter does a line check, executes it, then the next line check and so on.
so its better to get notified of errors in beginning itself rather than in between(as in interpreter).
optimystix
optimystix • Mar 1, 2010
ttyX
Isn't Java supposed to be both compiled & interpreted?
yes,like ashutosh said Java is both compiled and interpreted. Java was designed to be easy to use by coders and they wanted the advantages of both the compilers and interpreters . So they got both into one;-)

In java , the source code is 1st compiled into *.class file by java compiler (javac) and then this *.class file is interpreted and executed by Java Virtual Machine (JVM) as output
parth5508
parth5508 • Jul 21, 2011
compiler

1.compiler can take whole program to complie at a time and execute it.
2.compiler take less time to execute because it takes a whole prog. in a one time.
3.with the help of the compiler one time compile and without modification multitime.
4.compiler runs on compile code.
5.in a compiler there are several steps occur.1.lexical errors 2.syntax errors 3. symmentic errors. and than generate the intermediate code.
6.in a compiler optimize the code.
7.in a compiler reallocation required so it takes more memory.
8.whenevee complex structure complier is used.
9.for example: c,C#,java

interpreter
1.interpreter take line by line,detect errors and than execute it.
2.interpreter takes more time because of line by line execution.
execute.if you modify then again compile than execute.
3.in interpreter everything required for interpret.
4.interpreter runs on source code.
5.in a interpreter that is not generate the ic only three steps occur.
6.in ainterpreter no optimization code.
7.interpreter takes entire program in main memory so no allcation required.
8.whwnever command is used interpreter is used.
9.for example:basic
williamjacob
williamjacob • Jul 22, 2011
A compiler converts the entire program into executable code before running, when running the program only the executable version of the code is running.

An interpreter converts the code during run time, it converts the code 1 line at a time at the time that it is running.

_________________

In simple words, compiler is better than interpreter in terms of Performance and Timing. 😀
frost00
frost00 • Mar 24, 2012
This topic is pretty much covered, however as others have rightly said an interpreter reads the code line by line then executes it..I should add that only if it gets to that line will it be executed. For example there could be an if function with a syntax error in but if conditions are/aren't met then part of the if function won't run, i.e won't be intepreted

Share this content on your social channels -