Compiler vs Interpreter

Run the code below using different translators. Notice how they handle the SYNTAX ERROR on Line 4 differently.

game.py
print("Welcome")
load_graphics()
print("Start Game")
syntx_error("Oops")
print("Game Over")
Select a translator to start simulation...
Terminal Output

Observation Notes

Observe when the error is detected and how much of the code is executed before the program fails.

GCSE Computer Science: Compilers vs Interpreters

What is a Compiler?
A compiler is a translator program that converts the entirety of a high-level source code file into machine code all at once, before the program is executed. This process generates a standalone executable file (such as a .exe). Because the translation happens beforehand, compiled programs execute rapidly and the original source code is kept secure. However, the initial compilation process can be slow, and if there is a single syntax error anywhere in the file, the compiler will fail and no executable will be created.
What is an Interpreter?
An interpreter is a translator program that converts high-level source code into machine code line-by-line during execution. It reads a line, translates it, and immediately executes it before moving to the next. It does not create a standalone executable file. This makes interpreters excellent for debugging, as the program will run up until the exact point an error is found. However, because translation occurs simultaneously with execution, interpreted programs run significantly slower than compiled ones.
Why did the lab crash on Line 4?
In the simulation above, the Interpreter successfully translated and executed lines 1, 2, and 3. It only crashed when it reached the syntax error on line 4. This demonstrates how interpreters process code sequentially. The Compiler, however, scanned the entire document beforehand. It detected the syntax error on line 4 immediately and would refuse to build the program, meaning lines 1, 2, and 3 would never be executed at all.