Skip to main content

Main Differences between Interpreters and Compilers

The main difference between an interpreter and a compiler is that compilation requires analysis and the generation of machine code only once, whereas an interpreter may need to analyse and interpret the same program statements each time it meets them e.g. instructions appearing within a loop. For example the following Visual Basic code would be interpreted each time the loop is entered:

 
	For iCountvar = To 20
		iSum = iSum + iCountvar
		Pic.Display iSum
	Next iCountvar
 

This has implications for error reporting, eg: when an interpreter encounters an error it reports it to the user immediately and halts further execution of the program. Such instant feedback, pinpointing the exact location of the error, helps the programmer to find and remove errors.

Compilers, on the other hand, analyse the entire program, taking note of where errors have occurred, and places these in an error/diagnostic file. If errors have occurred then the program cannot run. Programmers must then use the error messages to identify and remove the errors in the source code. Some compilers assist by adding line numbers to the source listing to help pinpoint errors and all compilers will describe the nature of the error e.g. missing semi-colon, expected keyword, etc. - although interpreting some compiler diagnostics is a skill in itself.

Error correction can be very time-consuming and frustrating, particularly in the case where spurious errors occur, e.g. many errors are highlighted in the source but the cause of the error is a single, simple mistake. An example of this would be errors that are generated by, say, a compiler, if a programmer simply misses out a semi-colon.

Another important difference is that interpreters can be 2 to 10 times slower than compilers. One reason for this is that they translate the same statements within a loop over and over again. Compilers can produce much more efficient object code than interpreters thus making the compiled programs to run faster.

Interpreters however are easier to use, particularly for beginners, since errors are immediately displayed, corrected by the user, until the program is able to be executed. On the whole compilers tend to be more difficult to use.

Next: Differences between Client-side and Server-side Scripting