Learn to compare an interpreter and a compiler through clear examples and targeted practice.
Ontario Grade 11 Computer Science
Computer Environments and Systems
ICS3U study topic C3.4: Compare an interpreter and a compiler
A program is a set of instructions written in a programming language. A computer system must process those instructions so they can be carried out. An interpreter and a compiler are two approaches to processing a program. The central difference in this lesson is timing: an interpreter processes instructions as the program runs, while a compiler translates the program before the translated result is run. These are general descriptions; details vary among languages and tools. Python 3 examples below help us trace program behaviour. They are not claims about how every Python tool, or every classroom language, works.
What you will learn
Describe how an interpreter and a compiler process a program.
Compare the timing of interpretation and compilation.
Trace a short Python 3 program and state its expected output.
1. The basic comparison
An interpreter processes a program during its run, handling instructions as the program proceeds. A compiler translates a program before the translated result is run. In a typical compiled workflow, the source program is translated first, and then the translated result is run. In a typical interpreted workflow, an interpreter processes the source program as it runs.
A simple analogy is following directions as you go compared with preparing a translated copy before following it. The analogy is limited: computer tools process instructions, not meanings in the way people understand them. Use it only to remember the timing difference.
A programming language supplies rules for writing programs. An interpreter or compiler is a tool, or part of a system, that processes a program written in a language. The language and the processing tool are not the same thing. Actual systems can vary, so avoid saying that every language uses only one approach.
An interpreter processes instructions during a program run.
A compiler translates a program before the translated result is run.
The key comparison is when processing and translation happen.
2. Input, process, and output
For either approach, the input considered here is the source program: the instructions written by the programmer. In an interpreted path, an interpreter processes the source during the run, and the program can produce output. In a compiled path, a compiler translates the source first; the translated result is then run and can produce output.
The processing path and the program’s purpose are different ideas. If the source instructions ask to display a message, those instructions determine the intended message. Describing the program as interpreted or compiled explains how its source is processed; it does not, by itself, change the message the instructions ask to display.
The system diagrams in the examples show the two general paths. They are models of the comparison, not claims that every compiler produces the same kind of translated result or that all tools follow exactly the same steps.
Input: a source program.
Interpreted path: the source is processed during the run.
Compiled path: the source is translated first, then the translated result is run.
Trace the instructions to predict output; do not infer output from the processing approach.
3. Trace a short program
Python 3 provides a small example of source instructions. The print instruction displays the text or value supplied to it. Quotation marks identify text in the source code; they are not included in the displayed text. Python 3 uses this syntax, while other classroom languages may write a similar instruction differently.
To trace a program, read its instructions in order and keep track of values assigned to variables. An assignment stores a value under a variable name. A later print instruction can display that stored value. This is a way to predict an expected output from the source; it does not mean the code has been run.
After tracing the program’s intended behaviour, compare how each approach processes its source. The interpreter processes instructions during the run. The compiler translates the program before the translated result is run. Keep those processing descriptions separate from the trace of the program’s values.
Read instructions in order and track assigned values.
Python 3 syntax is language-specific; other classroom languages may differ.
A trace predicts an expected result without claiming actual execution.
4. Make a clear comparison
A clear comparison states both sides and identifies the contrast. For example: an interpreter processes instructions as a program runs, while a compiler translates a program before the translated result is run. This describes timing and the next step in the basic compiled workflow.
Do not say that an interpreter does no processing, or that a compiler runs the source before translating it. Also avoid unsupported claims that one approach is always faster or that every tool handles programs in exactly the same way. The selected comparison is about processing and translation.
When using an example, show the same source instructions and trace their expected output. Then explain the two processing paths. This makes clear that the source determines the intended behaviour, while the interpreter/compiler distinction describes how the source is handled.
State both descriptions and make their timing contrast explicit.
In the basic compiled workflow, the translated result is run.
Keep claims general and avoid ranking tools or languages.
Trace for the score program
Instruction processed
Value of score
Expected display
score = 12
12
Nothing displayed yet
print(score)
12
12
Worked example
Predicting a message
A Python 3 source program contains one instruction that displays the message Ready. Identify the source input, describe both processing paths, and give the expected output.
Two paths for one source program
The paths begin with the same source. Interpretation happens during the run; compilation translates first, then the translated result is run.
Python 3
print("Ready")
Identify the input
The input is the source program: the Python 3 instruction shown in the code field. There is no keyboard input in this example.
Trace the instruction
The instruction asks to display the text inside its parentheses. The quotation marks mark text in the source and are not part of the displayed message.
Compare the processing paths
An interpreter processes the instruction during the run. A compiler translates the source before the translated result is run. Tracing the instruction gives the expected output Ready in either description.
Answer: Expected output: Ready.
Check: The quotation marks belong to the source syntax, not to the displayed message.
Worked example
Tracing a variable value
A Python 3 program assigns 12 to score and then displays score. Trace the value and describe how an interpreter and a compiler process the source.
Processing a program that displays a value
Both paths start with the source that assigns and displays score. Their difference is processing timing.
Python 3
score = 12
print(score)
Read the assignment
The first instruction stores the value 12 in the variable score. After that instruction, score has the value 12.
Read the display instruction
The second instruction displays the value stored in score. Because score is not inside quotation marks, it refers to the variable rather than the text score.
Compare the processing paths
The expected output is 12. An interpreter processes the instructions during the run. A compiler translates the source before the translated result is run. The trace describes the intended behaviour of these instructions.
Answer: Expected output: 12.
Check: The assignment comes before the display instruction, so score contains 12 when it is displayed.
Worked example
Checking a comparison
A student says, “A compiler translates a program before it runs, while an interpreter processes it during the run.” Is this a useful comparison? Support your answer with a short source example and its expected output.
One source, two processing approaches
The same source is shown on both paths. The interpreter processes during the run; the compiler translates before the translated result is run.
Python 3
amount = 5
print(amount)
Evaluate the comparison
It is useful because it states the central timing contrast: an interpreter processes instructions during a run, while a compiler translates the program before the translated result is run.
Trace the example
The source assigns 5 to amount. The next instruction displays the value stored in amount, so the expected output is 5.
Keep the ideas distinct
The trace describes what the source instructions are intended to do. The interpreter and compiler descriptions explain different ways the source is processed. This comparison does not require claiming that every tool works identically.
Answer: Yes. It gives the central timing contrast. The example’s expected output is 5.
Check: A complete comparison describes both approaches without claiming that processing alone changes the intended output.
Common mistakes and how to avoid them
Saying an interpreter does not process a program.
Correction: Say that an interpreter processes instructions during the program run.
Saying a compiler runs the source before translating it.
Correction: In the basic compiled workflow, the compiler translates the program first, and the translated result is then run.
Assuming that interpreted and compiled approaches must produce different outputs.
Correction: The processing approach differs; the source instructions determine the program’s intended output.
Calling a programming language an interpreter or a compiler.
Correction: A language gives rules for writing programs; an interpreter or compiler is a tool or part of a system that processes them.
Lesson summary
An interpreter processes instructions as a program runs.
A compiler translates a program before the translated result is run.
Both descriptions concern how source instructions are processed.
Trace the source to predict output, and distinguish that prediction from the processing approach.
Check your understanding
Question 1
Which statement best describes the main difference in this lesson?
An interpreter processes instructions during a run; a compiler translates the program before the translated result is run.
An interpreter changes the intended output, while a compiler preserves it.
A compiler is a programming language, while an interpreter is a computer.
An interpreter must display every source instruction.
Show answer and explanation
An interpreter processes instructions during a run; a compiler translates the program before the translated result is run.
The comparison is about timing: an interpreter processes during a run, while a compiler translates before the translated result is run.
Question 2
What is the expected output of the Python 3 instruction print("Go")?
print("Go")
Go
"Go" including quotation marks
Nothing, because print assigns a value
Show answer and explanation
Go
The instruction displays the text inside the quotation marks. The quotation marks are source syntax, not part of the displayed message.
Question 3
In the basic compiled workflow described here, what happens after the compiler translates the source program?
The translated result is run.
The programming language becomes the output.
The source instructions are assumed to have no effect.
The output is converted back to source before running.
Show answer and explanation
The translated result is run.
The basic workflow is translation first, followed by running the translated result.
Key terms
Source program
Instructions written by a programmer in a programming language.
Interpreter
A tool or part of a system that processes program instructions as the program runs.
Compiler
A tool or part of a system that translates a program before the translated result is run.
Output
Information produced by a program, such as a message displayed on a screen.
Published by DoAssignment. This reviewed lesson follows Ontario Grade 11 Computer Science (ICS3U), expectation C3.4. It is a study resource, not an official curriculum publication.
Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.