GCSE · Computer Science · OCR · Spec J277
Compiler
You've written a program in words like print and score. Your computer can't execute a single one of them as they are. So how does your program ever run?
Follow one program
From your code to one executable file
A tiny three-line program written in a high-level language. Step through what happens when it's compiled, then run.
Before each Next, predict: what exists after this step?
1 score = 02 score = score + 103 print("Your score: " + str(score))
| Stage | What happens | What you've got |
|---|---|---|
| 1. Write | You type the program | High-level code |
Output
Step 1: Three lines of words and commands: score, print, str. Easy for you to read. The computer can't execute them as written. They have to be translated into machine code first.
Each Next adds one stage to the table. Nothing here is run by the page: every row is the lesson's.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
You write code in words. The computer runs binary. Something has to translate, and a compiler does the whole program in one go.
What you need to know
- High-level languages are written in words and commands closer to human language.
- The computer can't execute high-level code as written. It has to be translated into machine code first.
- Machine code means binary instructions: the code the computer can actually execute.
Have a goYour friend points at score = score + 10 and says, "That's machine code, it's what the computer runs." Is it?
No. It's high-level code.
It's written in words and symbols you can read. Machine code is binary instructions, and this line has to be translated before the computer can execute it.
- Two translators can do that job: a compiler or an interpreter.
- A compiler translates the whole program into machine code, all at once.
- An interpreter translates the program line by line instead.
Have a goA translator works through a 200-line program: line 1, then line 2, then line 3… Compiler or interpreter?
Interpreter.
Line by line is how an interpreter translates. A compiler would translate all 200 lines in one go.
- Compiling creates a single executable file for the program.
- That executable file can be run without the original code.
Have a goMo compiles his game, then deletes the folder with his original code in it. Panic! Can he still run the executable file?
Yes.
The executable file is the program already translated into machine code, so it can be run without the original code.
The big picture
A high-level language is written in words and commands closer to human language. The computer can't execute that as written: it has to be translated into machine code, the binary instructions the computer can execute. A compiler and an interpreter both do this translation, but in different ways. A compiler translates the whole program into machine code all at once and creates a single executable file, which can be run without the original code. An interpreter translates the program line by line.
Key points
Worked example
Problem
A student wrote: "A compiler and an interpreter both translate high-level code, but a compiler goes line by line and an interpreter does the whole program at once." Find what's wrong and write a corrected answer.
⚠ Watch out
Swapping the two methods. A compiler translates the whole program at once; it's the interpreter that goes line by line.
Memory hook
Compiler = Complete: the complete program translated in one go, leaving one file that runs on its own.
Check yourself
Cover the page. In one sentence each: why does high-level code need translating, what does a compiler create, and how does its method differ from an interpreter's?
Flashcards
(8)What is a compiler?
How much of a program does a compiler translate at a time?
How does an interpreter translate a program?
What file does a compiler create?
Does the executable file need the original code to run?
High-level language
Machine code
Why can't the computer just run high-level code as it's written?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 4 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.