Translators: compilers, interpreters and assemblers
Computer Science · GCSE · The School
A CPU only understands machine code
A CPU executes MACHINE CODE. That is binary instructions specific to that processor. Source code, written in a language like Python or Java, is for humans to read, not for a CPU to run directly. A TRANSLATOR converts source code into a form the machine can actually execute, before any of it can run.
A compiler translates everything, then runs it
A COMPILER reads the entire program once. It translates it fully into machine code, and produces a standalone executable file. Running the program afterwards needs no further translation. That makes it fast to run, but slow to change: any edit means recompiling the whole program again, from the start.
An interpreter translates and runs one line at a time
An INTERPRETER reads and executes each line in turn, translating it on the spot. No separate executable file gets produced. This makes testing quick — change one line, run it immediately. But the program runs slower overall, since every line is retranslated every single time it executes, even lines run many times over.
A worked comparison: choosing between them
A game studio finalising a product compiles it. Players need speed, not the ability to edit the code. A compiled file also hides the source from easy copying. A programmer testing new code often prefers an interpreter instead. Seeing the effect of one small change immediately speeds up finding and fixing errors, before a whole build is worth waiting for.
An assembler is a translator for a different language
ASSEMBLY LANGUAGE sits between machine code and a high-level language. Mnemonics like ADD or MOV stand for individual machine instructions, in a near-one-to-one relationship. An ASSEMBLER translates assembly language into machine code. It is a distinct kind of translator, since assembly is already extremely close to what the CPU runs, with almost no simplification left to do. Writing directly in assembly is rare today, reserved mostly for the smallest, most performance-critical parts of a system.
Errors: when each translator reports them
A compiler reports errors after reading the WHOLE program, before anything runs at all. A single typo on line 1 of 500 stops the whole program from running. An interpreter only reports an error once it reaches that specific line. So a program can run fine for a while, then suddenly fail partway through, right at the line where the error sits.