Compilers & Interpreters
- Programmers will write program source code using high-level languages e.g. Python, Java, C# etc. As programmers, we can understand source code as it is descriptive, easy to read, maintain and debug. However this is not good for the hardware as it needs to be converted into binary to allow the hardware to understand and execute it, this is known as machine code. For this to work it needs to pass through a translator first. There are two types of translators - a compiler and an interpreter
Compiler
- This method will translate a program into machine code. Compilers convert the source code in one go into an executable file ready for distribution. This method is used mainly when a program is finished with no syntax or logical errors
- Compiling may take time to be processed, however, this can be used over without needing to be recompiled every time, bearing in mind that the program contains no errors
- Error reports are produced after a program has been translated. Common errors in code will allow the computer to crash and not respond, it’s important to be aware that if there are errors the source code must be changed to compile again
Interpreter
- This is the method that directly sends the source code to the machine code. This will translate each line of code individually, if an error occurs the program will stop and an error message will occur. Once the error message is fixed, the program can carry on running from where the error occurred
Exam Tip
- You will need to have a good understanding of the difference between a compiler and an interpreter. You will need to focus on features of compilers and interpreters or focusing on an overall comparison between the two
- Although both translators find errors in code, they do not debug the errors - this is done by the programmer