1. Interpreters
An interpreter translates and executes a program one statement at a time. It does not produce a translated version of the program, so no executable file is made.
It stops when an error is found. The error can be corrected in real time and the program continues from that point. Only one error is displayed at a time, and a partly written program can be tested on its own.
A compiler translates all the code at the same time and creates an executable file. Some high-level languages are partially compiled and partially interpreted. Partially compiled programs can be used on different platforms, as they are interpreted when run.
Examiner insight
Worked example 14 marks
A programmer uses both a compiler and an interpreter to translate a program written in a high-level language.
Describe the advantages of using the interpreter compared to the compiler to translate the program.
- 1
The interpreter is easier to debug with: it translates line by line and stops when an error is found, whereas the compiler translates all the program at the same time [1]
- 2
It reports one error at a time [1]
- 3
The error can be corrected in real time and the program restarts at the same point, whereas with a compiler the program has to be corrected, recompiled and re-run [1]
- 4
A partially completed program can be translated and tested on its own, but a compiler cannot translate a partial program [1]