Compiler

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

Compiler

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A compiler translates a high-level program...
A All at once, as a whole, before the program runs
B One line at a time while the program runs
2. What does a compiler produce from a high-level language program?
A Another high-level program
B Machine code
3. When does the compiler's translation happen?
A Before the program is executed
B While the program is being executed
4. Once a program has been compiled, the student wants to run it on another computer of the same type. What is needed?
A Only the compiled machine code (executable file)
B The source code and the compiler
5. Which translator converts assembly language into machine code?
A Compiler
B Assembler

Match the Pairs

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

Left columnRight column
1compiler AA translator that converts a whole high-level program into machine code before the program is run
2source.c -> compiler -> program.exe BThe compiled machine code can run on its own. The source code is not needed to run it.
3A compiler translates the whole program in one go, before any of it is run Ccompiler: high-level -> machine code; assembler: assembly -> machine code
4A compiler turns high-level code into machine code, but an assembler turns assembly language into machine code DThis describes an interpreter, not a compiler. A compiler translates the whole program before it runs.
5A compiler translates and runs the program one line at a time Ecompile(whole_program) THEN run(machine_code)
6The program only works if the source code is kept with the compiled file FThe compiler translates all the source code into an executable file, which can run without the source code

Definitions

compiler

Fill in the Blanks

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

1.
source code -> ________ -> machine code
2.
high-level program -> compiler -> ____________
3.
compile(source) delete(source) ___(program_exe)
4.
compiler: translates ___ of the code at once
5.
compiler input: __________ language

Spot the Error

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

Question 1
A INPUT source
B exe <- ASSEMBLE(source)
C SAVE exe AS "game.exe"
D RUN "game.exe"
Question 2
A source <- READ "calc.txt"
B exe <- COMPILE(source)
C SAVE exe AS "calc.exe"
D RUN "calc.txt"
Question 3
A timing <- "before running"
B needs_source <- FALSE
C whole_program <- FALSE
Question 4
A input <- "machine code"
B translator <- "compiler"
C output <- "machine code"
Question 5
A source <- LOAD "app.src"
B exe <- COMPILE(source[1])
C SAVE exe AS "app.exe"

Answer Key

Compiler
Section A: Quick Questions
Q1
A — All at once, as a whole, before the program runs
Q2
B — Machine code
Q3
A — Before the program is executed
Q4
A — Only the compiled machine code (executable file)
Q5
B — Assembler
Section B: Match the Pairs
Q1
compiler → A translator that converts a whole high-level program into machine code before the program is run
Q2
source.c -> compiler -> program.exe → The compiler translates all the source code into an executable file, which can run without the source code
Q3
A compiler translates the whole program in one go, before any of it is run → compile(whole_program) THEN run(machine_code)
Q4
A compiler turns high-level code into machine code, but an assembler turns assembly language into machine code → compiler: high-level -> machine code; assembler: assembly -> machine code
Q5
A compiler translates and runs the program one line at a time → This describes an interpreter, not a compiler. A compiler translates the whole program before it runs.
Q6
The program only works if the source code is kept with the compiled file → The compiled machine code can run on its own. The source code is not needed to run it.
Section C: Definitions
Q1
compiler — A translator that converts a whole high-level language program into machine code in one go, before the program is run. The machine code can then run without the source code.
Section D: Fill in the Blanks
Q1
source code -> compiler -> machine code
Q2
high-level program -> compiler -> machine code
Q3
compile(source) delete(source) run(program_exe)
Q4
compiler: translates all of the code at once
Q5
compiler input: high-level language
Section E: Spot the Error
Q1
B — An assembler translates assembly language, not a high-level program. A high-level program needs a compiler, so the line should be exe <- COMPILE(source).
Q2
D — The source file is not machine code, so it cannot be run directly. After compiling, the program must run the executable: RUN "calc.exe".
Q3
C — A compiler translates the whole program in one go. whole_program should be TRUE, not FALSE.
Q4
A — A compiler takes high-level source code as its input and produces machine code as its output. Machine code is the output, not the input.
Q5
B — A compiler translates the whole program at once, not just one line. It should be exe <- COMPILE(source).