Comparing a compiler and an interpreter

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Comparing a compiler and an interpreter

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which translator converts the whole program into machine code before it runs?
A A compiler
B An interpreter
2. Which translator works through the code line by line, translating and running each line in turn?
A A compiler
B An interpreter
3. Which translator produces an executable file that can be run without the source code?
A A compiler
B An interpreter
4. A student wants to give a finished program to a friend who does not have the source code or any translator. Which statement is correct?
A Compile it and share the executable file
B Share it and let the friend use an interpreter on the source code
5. A program has three syntax errors. Which translator reports all of them together after attempting to translate the whole program?
A An interpreter
B A compiler

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1compiler: translates the whole program AThe compiler translates all of the source code in one go and produces an executable file, which can then be run without the compiler or the source code.
2interpreter: translates line by line BCompiler: Error on line 3, Error on line 9, Error on line 14
3A compiler gives a full list of errors after it has tried to translate the whole program CInterpreter: Error on line 3 - stopped
4An interpreter stops at the first error it meets, so later lines are not checked until that one is fixed DA compiled program is translated once into an executable, so it runs without further translation and is usually faster. An interpreted program is translated every time it runs.
5An interpreter creates an executable file that can be sent to other users EThe interpreter translates one statement, runs it, then moves to the next. It produces no executable file, so the source code and interpreter are needed every time.
6A compiled program must be translated again every time it is run, so it runs more slowly than an interpreted one FAn interpreter does not create an executable file. Only a compiler does. Users need the interpreter and the source code to run the program.

Definitions

compiler vs interpreter

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Compiler: translates the _____ program
2.
Interpreter: translates line by ____
3.
Compiler produces an __________ file
4.
Interpreter stops at the _____ error
5.
Compiled code runs ______ than interpreted

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A compiler:
B translates: whole program
C executable: yes
D errors: stops at first one
Question 2
A interpreter:
B translates: line by line
C executable: yes
D errors: stops at first one
Question 3
A IF translator = compiler THEN
B translate whole program
C ELSE
D translate the whole program
E ENDIF
Question 4
A Speed: compiled code is slower
B Reason: already translated
C Interpreted code: translated
D again every time it runs
Question 5
A Compiler error report:
B stops after the first error
C fix them, then recompile

Answer Key

Comparing a compiler and an interpreter
Section A: Quick Questions
Q1
A — A compiler
Q2
B — An interpreter
Q3
A — A compiler
Q4
A — Compile it and share the executable file
Q5
B — A compiler
Section B: Match the Pairs
Q1
compiler: translates the whole program → The compiler translates all of the source code in one go and produces an executable file, which can then be run without the compiler or the source code.
Q2
interpreter: translates line by line → The interpreter translates one statement, runs it, then moves to the next. It produces no executable file, so the source code and interpreter are needed every time.
Q3
A compiler gives a full list of errors after it has tried to translate the whole program → Compiler: Error on line 3, Error on line 9, Error on line 14
Q4
An interpreter stops at the first error it meets, so later lines are not checked until that one is fixed → Interpreter: Error on line 3 - stopped
Q5
An interpreter creates an executable file that can be sent to other users → An interpreter does not create an executable file. Only a compiler does. Users need the interpreter and the source code to run the program.
Q6
A compiled program must be translated again every time it is run, so it runs more slowly than an interpreted one → A compiled program is translated once into an executable, so it runs without further translation and is usually faster. An interpreted program is translated every time it runs.
Section C: Definitions
Q1
compiler vs interpreter — A compiler translates the whole program into an executable before it runs; an interpreter translates and runs line by line, stopping at the first error, with no executable.
Section D: Fill in the Blanks
Q1
Compiler: translates the whole program
Q2
Interpreter: translates line by line
Q3
Compiler produces an executable file
Q4
Interpreter stops at the first error
Q5
Compiled code runs faster than interpreted
Section E: Spot the Error
Q1
D — A compiler translates the whole program, so it reports all the errors it finds together. Stopping at the first error is what an interpreter does. It should say 'errors: full list reported'.
Q2
C — An interpreter translates and runs the code each time and does not produce an executable file. It should say 'executable: none'.
Q3
D — The ELSE branch covers the interpreter, which translates one line at a time. Translating the whole program is the compiler's job in the first branch.
Q4
A — Compiled code is already translated into an executable, so it usually runs faster. An interpreter has to translate the code again each run, which makes it slower. Line 1 should say 'faster'.
Q5
B — A compiler gives a full error report after it has tried to translate the whole program. Stopping at the first error describes an interpreter.