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?

Compiler or interpreter?

Same job, different method

Two translators. For each statement, tick compiler, interpreter, or both. Careful: some statements are true of both.

  • A Compiler
  • B Interpreter
  1. Translates a high-level language into machine code
  2. Translates the whole program at once
  3. Translates the program line by line
  4. Creates a single executable file
  5. Leaves something that can be run without the original code
  6. Has to deal with high-level code before the computer can execute it

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 = 0
2 score = score + 10
3 print("Your score: " + str(score))
StageWhat happensWhat you've got
1. WriteYou type the programHigh-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.

1 / 4

Each Next adds one stage to the table. Nothing here is run by the page: every row is the lesson's.

Step 1 of 4: 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..

Watch out: The executable file holds the program in machine code. It isn't a shortcut back to your original code, which is why it can be run without it.

What do you think?

Jas presses compile

Jas has written a quiz game in a high-level language. She presses the button to compile it.

Which idea is closest to what you think is happening?
How sure are you?

Your turn

Write it, then mark it

Leo has finished writing a drawing app in a high-level language. He uses a compiler on it. Describe what the compiler does to Leo's app and what Leo ends up with. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

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

1High-level code has to be translated into machine code (binary instructions) before the computer can execute it.
2A compiler and an interpreter both translate high-level code into machine code.
3A compiler translates the whole program at once; an interpreter translates it line by line.
4A compiler creates a single executable file, which can be run without the original code.

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?
A translator that creates an executable file for a program by translating a high-level language into machine-readable code.
How much of a program does a compiler translate at a time?
The whole program, into machine code, all at once.
How does an interpreter translate a program?
Line by line.
What file does a compiler create?
A single executable file.
Does the executable file need the original code to run?
No. It can be run without the original code.
High-level language
A language written in words and commands closer to human language.
Machine code
Binary instructions that the computer can execute.
Why can't the computer just run high-level code as it's written?
It has to be translated by a compiler or an interpreter into machine code, which the computer can execute.

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 posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

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.