The shape of the lesson
By the end of the lesson, learners can
- Three translators: Which translator you need depends on the language the source code is written in.
- How errors are reported: Here is a short program with mistakes on lines 2 and 4.
- Compiler or interpreter?: Both have strengths.
- Assembler: assembly language to machine code.
- Compiler: whole high-level program at once; executable file; error report for the whole code.
- Interpreter: translates and executes line by line; stops at the first error.
- Use: interpreter while developing; compiler for the final program.
One picture every idea returns to
A translator turns source code into machine code. An assembler translates assembly language. A compiler translates the whole high-level program at once before it is executed, producing an executable file; if there are errors it gives an error report for the whole code. An interpreter translates and executes the code line by line and stops when it finds an error. An interpreter is mostly used while developing a program; a compiler is used to translate the final program.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, All at once, or line by line.. Every program has to become machine code before the processor can run it. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Three translators | Which translator you need depends on the language the source code is written in. | Whole class, then pairs |
| 13 to 21 min | Teach and check: How errors are reported | Here is a short program with mistakes on lines 2 and 4. Model the worked example Compiler on the board, one line at a time. | Pairs |
| 21 to 30 min | Teach and check: Compiler or interpreter? | Both have strengths. Your turn: A developer is still writing and testing a game. Which translator is more useful now, and why? | Think-Pair-Share |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 16 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Compiler or interpreter?, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Think-Pair-Share
Pose the question, give thirty seconds of silent thinking, then a minute to compare with a partner before a few pairs share with the class. The silent minute is the part that cannot be cut.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| An assembler is never used for a high-level language, and a compiler or interpreter is never used for assembly language. | Match the translator to the language. |
| A compiler does not run the program while it is translating. | It reports all the errors it can find, and only an error-free program becomes an executable file. |
Assemblers, compilers and interpreters: worksheet
6 questions, 16 marks. Written in the style of the papers; no past paper question is reproduced.
Describe how a compiler translates a high-level language program and how it reports errors.
Describe how an interpreter translates a high-level language program and how it reports errors.
State the type of translator needed for: (a) a program written using mnemonics such as LDD and ADD; (b) a program written in Python that is to be sold as an executable file.
Give two advantages of a compiler and two advantages of an interpreter.
A programmer uses an interpreter while writing an app and a compiler when the app is finished. Explain why.
A program is run with an interpreter. It outputs two lines and then stops with an error message. When the same program is compiled, nothing is output at all. Explain the difference.
Answer key and marking notes
- It translates the whole program at once, before it is executed.
- It produces an executable file (machine code).
- If errors are detected it produces an error report for the whole code (and no executable).
- It translates one line of code and then executes it,
- before moving on to the next line (line by line).
- It stops execution when an error is found and reports that error.
- (a) Assembler.
- (b) Compiler.
- Compiler: produces an executable file that runs without the translator / runs faster once compiled.
- Compiler: the source code is not given to users, so it cannot easily be copied or changed.
- Interpreter: stops at the error, so it is easy to see where the error is.
- Interpreter: code can be tested line by line / in parts during development, without translating the whole program.
- During development an interpreter helps debugging, because it stops at each error and parts of the code can be tested as they are written.
- When finished, a compiler produces an executable file to distribute, which runs quickly without the source code or a translator.
- The interpreter executed the lines before the error, producing output, then stopped at the error.
- The compiler translates the whole program first; because there is an error no executable is produced, so nothing runs and only an error report is given.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
How does an interpreter translate a high-level program?
- AIt translates and executes one line at a time, stopping when it finds an error
- BIt translates the whole program at once and produces an executable file
- CIt converts each mnemonic into a single machine code instruction
- DIt lists every error in the program before running any of it
A program for a games console is written using mnemonics such as LDD, ADD and STO. Which translator is needed before it can run?
- AAn assembler
- BA compiler
- CAn interpreter
- DA bootloader
Line 04 of this program is missing a closing quotation mark. The program is run using an interpreter.
01 Score ← 5 02 OUTPUT Score 03 OUTPUT Score * 2 04 OUTPUT "Done 05 OUTPUT Score + 1What happens?
- A5 and 10 are output, then the interpreter stops and reports the error in line 04
- BNothing is output, and an error report for the whole program is shown
- C5, 10 and 6 are output, and line 04 is skipped
- DAn error is reported at line 01, before anything is output
What does a compiler produce when it translates a program that has no errors?
- AAn executable file
- BAn error report for each line
- CA list of mnemonics
- DA device driver
The same program is compiled instead of interpreted.
01 Score ← 5 02 OUTPUT Score 03 OUTPUT Score * 2 04 OUTPUT "Done 05 OUTPUT Score + 1What happens?
- ANo executable file is produced, nothing is output and the error in line 04 is reported
- B5 and 10 are output, then the compiler stops at line 04
- CThe compiler fixes line 04 automatically and then outputs 5, 10, Done and 6
- DAn executable file is produced and the error only appears when it is run
A company has finished writing a game. It wants customers to run it quickly without being able to see or change the source code. Which translator should it use for the final version, and why?
- AA compiler, because customers receive only the executable file, which runs without translation
- BAn interpreter, because it stops at errors so customers can fix them
- CA compiler, because it translates and runs the code one line at a time
- DAn interpreter, because it creates an executable that hides the source code
Quiz key
An interpreter translates one line, executes it, then moves on, and stops at the first error it meets. Translating everything at once into an executable and listing all errors in one report describe a compiler. Converting mnemonics into machine code is what an assembler does.
Mnemonics are assembly language, which is translated into machine code by an assembler. Compilers and interpreters translate high-level languages, never assembly language. A bootloader is firmware that loads the OS; it is not a translator.
The interpreter translates and runs lines 01 to 03, so 5 and then 10 are output. At line 04 it finds the error, stops and reports it, so line 05 is never reached. Producing no output and one report for the whole code is how a compiler behaves. An interpreter does not skip errors, and lines 01 to 03 contain no error.
A compiler translates the whole program into machine code saved as an executable file, which can be run again and again without translating. An error report is only produced when errors are found. Mnemonics belong to assembly language, and device drivers are a type of system software.
A compiler checks the whole program before running any of it. Because line 04 contains an error, it gives an error report and produces no executable, so nothing is output at all. Outputting 5 and 10 first is interpreter behaviour. Compilers do not fix errors themselves, and an executable is only created from error-free code.
A compiler produces an executable file: it runs quickly because no translation is needed each time, and customers never receive the source code. An interpreter would need the source code and the interpreter on each customer's machine, and its stopping at errors helps developers, not customers. Line-by-line execution describes an interpreter, and interpreters do not produce executables.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.