Scribe logoScribeNotes & practice
Sign inStart free
  1. Notes
  2. ›IB Computer Science
  3. ›A1 Computer fundamentals
  4. ›A1.4 Translation

IB Computer Science · A1 · Computer fundamentals

A1.4 Translation

Explain why programs need translating, compare assemblers, compilers and interpreters, and describe the stages of compilation and when each method suits.

  • 4 min read
  • 5 parts
  • 10 questions
  • Draft
  • HL only
Start a Quick 5 on this topic→Jump to the 10 questions
1/5Processors run only machine code, so programs need translating
  1. 1Processors run only machine code, so programs need translating
  2. 2An assembler converts assembly language into machine code
  3. 3Compilers translate first and interpreters translate as they run
  4. 4Compilation passes through six stages, from tokens to machine code
  5. 5The best translation method depends on the situation
  6. Check your recall
  7. Practice: 10 questions
1

Part 1 of 5: Processors run only machine code, so programs need translating

A CPU can execute only instructions written in binary. These instructions are called machine code. Writing programs in machine code is slow and error-prone for people.

Programmers therefore write source code in a high-level language, which uses readable words and statements. A translator is a program that converts source code into machine code or another lower-level form.

A line such as total = price * 2 is easy to read, but a CPU cannot run it. Translation lets the same readable program be turned into instructions for a particular processor.

Key terms · tap one for its definition

machine code

Machine code is the binary instruction set that a particular CPU can execute directly.

source code

Source code is a program written by a programmer in a programming language, before it is translated.

translator

A translator is a program that converts source code written in one language into another form, usually machine code.

Part 1 done

2

Part 2 of 5: An assembler converts assembly language into machine code

Between machine code and high-level languages sits a middle form. In assembly language, short codes such as ADD or LOAD replace binary patterns, so people can read them.

Each assembly instruction matches one machine instruction. An assembler converts assembly language into machine code. Because the match is one to one, the programmer keeps close control of what the CPU does.

Assembly language is tied to one type of processor, so it is not portable between processor types.

Common mistake

An assembler is not a compiler. It works on assembly language, usually one instruction to one instruction.

Key terms · tap one for its definition

assembly language

Assembly language is a low-level language in which short mnemonic codes each correspond to one machine code instruction.

assembler

An assembler is a translator that converts assembly language into machine code.

Part 2 done

Quick check

One question on the part you just read

Easy

Identify the only form of program that a CPU can execute directly.
Show answer and explanation

Answer: B · Worked explanation

A CPU can execute only machine code, which is written in binary. Source code and high-level languages must be translated first. Assembly language is closer to the hardware, but its short codes still have to be converted by an assembler before the CPU can run them.
3

Part 3 of 5: Compilers translate first and interpreters translate as they run

Now compare the two translators used for high-level code. A compiler translates the whole source program into machine code before it runs. The result is an executable, a separate file of machine code that can be run later.

An interpreter translates one statement, runs it, then moves to the next. It produces no separate executable. The interpreter and the source code are needed every time the program runs. That repeated translation is why interpreted programs usually run more slowly.

Compiler compared with interpreter

FeatureCompilerInterpreter
TranslationWhole program, before runningOne statement at a time, while running
OutputA separate executableNone; statements run directly
Speed of runningUsually fasterUsually slower
ErrorsReported together after translationFound as each statement is reached
Feature
Translation
Compiler
Whole program, before running
Interpreter
One statement at a time, while running
Feature
Output
Compiler
A separate executable
Interpreter
None; statements run directly
Feature
Speed of running
Compiler
Usually faster
Interpreter
Usually slower
Feature
Errors
Compiler
Reported together after translation
Interpreter
Found as each statement is reached

Common mistake

A compiler does not run the program. It only translates it, and the executable is run afterwards.

Key terms · tap one for its definition

compiler

A compiler is a translator that converts an entire source program into machine code before the program is run.

interpreter

An interpreter is a translator that translates and executes source code one statement at a time, without producing a separate executable.

Part 3 done

4

Part 4 of 5: Compilation passes through six stages, from tokens to machine code

A compiler does not translate in one jump. It works through stages, and each stage hands its output to the next.

  • In lexical analysis, the compiler splits the source code into tokens, the smallest meaningful units, such as keywords and names.
  • In syntax analysis, it checks that the tokens follow the grammar rules and builds a tree of the program.
  • In semantic analysis, it checks meaning, such as matching data types and declared variables.
  • In intermediate code generation, it produces a simple form that does not depend on the processor.
  • In optimisation, it improves the code so that it runs faster or uses less memory.
  • In code generation, it produces the final machine code.
Figure 1. A compiler passes the program through each stage in turn, and each stage uses the output of the one before.

Key terms · tap one for its definition

lexical analysis

Lexical analysis is the compilation stage that splits source code into tokens and discards items such as spaces and comments.

syntax analysis

Syntax analysis is the compilation stage that checks tokens against the grammar rules of the language and builds a parse tree.

semantic analysis

Semantic analysis is the compilation stage that checks that statements are meaningful, for example that data types match and variables are declared.

Part 4 done

Quick check

One question on the part you just read

Easy

Identify the translator that converts assembly language into machine code.
Show answer and explanation

Answer: C · Worked explanation

An assembler converts assembly language into machine code, usually one instruction to one instruction. A compiler works on high-level source code and an interpreter runs it statement by statement. An operating system manages the computer and is not a translator.
5

Part 5 of 5: The best translation method depends on the situation

Knowing how each translator works, you can match a method to a job. A compiler suits finished software. The user runs the executable without any translator, and the source code stays private.

The executable is made for one type of processor, so it must be compiled again for another. It usually runs faster.

An interpreter suits development and learning. A programmer can run a change straight away and see exactly where an error occurs. The same source code can run on any machine that has the interpreter.

Exam tip

Tie each choice to a situation. ‘An interpreter suits testing because errors appear as each line runs’ is better than ‘it is easier’.

An assembler suits work close to the hardware, such as small devices built into other products. There, each instruction matters.

Go deeperBytecode and virtual machines

Some languages mix both methods. A compiler turns the source code into bytecode, a compact intermediate form. A virtual machine, which is a program that imitates a computer, then runs the bytecode.

This gives one compiled file that can run wherever a suitable virtual machine exists. Java is a well-known example.

Note read

Check your recall[14 marks]

6 written questions. Answer each one in your head or on paper, then open the mark scheme.

  1. 1.State[1 mark]

    State why source code must be translated before a CPU can run it.

    Show mark schemeHide mark scheme

    Model answer

    A CPU can execute only machine code, which is binary, and source code is not written in that form.

    • 1 mark for stating that the CPU can execute only machine code (binary instructions)
  2. 2.Distinguish[3 marks]

    Distinguish between a compiler and an interpreter.

    Show mark schemeHide mark scheme

    Model answer

    A compiler translates the whole source program into an executable before it runs, and the executable can be run without the compiler. An interpreter translates and runs one statement at a time and produces no separate executable.

    • 1 mark for stating that a compiler translates the whole program before it runs
    • 1 mark for stating that an interpreter translates and executes one statement at a time
    • 1 mark for stating that a compiler produces a separate executable but an interpreter does not
  3. 3.Describe[2 marks]

    Describe the role of an assembler.

    Show mark schemeHide mark scheme

    Model answer

    An assembler converts assembly language into machine code. Each assembly instruction usually matches one machine instruction.

    • 1 mark for stating that it converts assembly language into machine code
    • 1 mark for stating that each assembly instruction matches one machine instruction
  4. 4.Outline[3 marks]

    Outline the purpose of lexical analysis and of syntax analysis.

    Show mark schemeHide mark scheme

    Model answer

    Lexical analysis splits the source code into tokens such as keywords, names and operators. Syntax analysis checks that the tokens follow the grammar rules and builds a tree of the program.

    • 1 mark for stating that lexical analysis splits the source code into tokens
    • 1 mark for stating that syntax analysis checks the tokens against the grammar rules
    • 1 mark for stating that syntax analysis builds a tree (parse tree) of the program
  5. 5.Justify[4 marks]

    Justify why a programmer might use an interpreter while developing a program but release it as a compiled executable.

    Show mark schemeHide mark scheme

    Model answer

    An interpreter lets the programmer run a change straight away and see where an error occurs, which suits development. A compiled executable usually runs faster. Users can run it without any translator, and the source code stays private.

    • 1 mark for stating that an interpreter allows a change to be run straight away
    • 1 mark for stating that an interpreter shows where an error occurs as the code runs
    • 1 mark for stating that a compiled executable usually runs faster
    • 1 mark for stating that users need no translator and the source code stays private
  6. 6.Identify[1 mark]

    Identify the stage of compilation that checks that data types match.

    Show mark schemeHide mark scheme

    Model answer

    Semantic analysis.

    • 1 mark for identifying semantic analysis

Practice this topic

10 quick-fire multiple-choice questions, easy to hard. Tap an answer to see if you're right and the worked explanation. (The written questions with mark schemes are under “Check your recall” above.)

0 right0 of 10 answered

Includes the 2 quick checks in the note above.

3.

Easy·Identify[1 mark]

Identify the translator that translates and runs source code one statement at a time.
Show answer and explanation

Answer: D · Worked explanation

An interpreter translates one statement, runs it, then moves to the next. A compiler translates the whole program first. An assembler handles assembly language, and lexical analysis is a stage inside compilation rather than a translator.
4.

Medium·Identify[1 mark]

Identify the compilation stage that splits source code into tokens.
Show answer and explanation

Answer: D · Worked explanation

Lexical analysis splits the source code into tokens, such as keywords, names and operators. Syntax analysis comes after it and checks the tokens against the grammar. Semantic analysis checks meaning, and optimisation improves the code later in the process.
5.

Medium·Identify[1 mark]

A statement uses a variable that was never declared, although the grammar of the statement is correct. Identify the stage most likely to detect the problem.
Show answer and explanation

Answer: C · Worked explanation

Semantic analysis checks meaning, including that variables are declared and data types match. The statement follows the grammar, so syntax analysis finds no fault. Lexical analysis only splits the code into tokens, and code generation happens after checking is complete.
6.

Medium·Identify[1 mark]

A company sells software. It does not want customers to need a translator or to see the source code. Identify the most suitable translator.
Show answer and explanation

Answer: B · Worked explanation

A compiler produces an executable that customers run without any translator, and the source code stays private. An interpreter would need the source code and the interpreter on every customer’s machine. An assembler works on assembly language, and syntax analysis is only one stage of compilation.
7.

Medium·Distinguish[1 mark]

Distinguish a compiler from an interpreter. Which statement is correct?
Show answer and explanation

Answer: B · Worked explanation

A compiler translates the whole program before it runs, and an interpreter translates and runs one statement at a time. The reversed statement swaps the two methods. Only a compiler produces a separate executable, and interpreted programs usually run more slowly because of the repeated translation.
8.

Hard·Deduce[2 marks]

Deduce the correct order of the stages that a compiler follows, from source code to machine code.
Show answer and explanation

Answer: A · Worked explanation

The source code is split into tokens, then checked for grammar, then for meaning. Intermediate code is generated, optimised, and finally turned into machine code. Putting syntax analysis first fails because there are no tokens yet, and optimising before an intermediate form exists, or checking meaning before grammar, breaks the order.
9.

Hard·Explain[2 marks]

Explain why an interpreted program usually runs more slowly than the same program compiled.
Show answer and explanation

Answer: A · Worked explanation

An interpreter needs the source code and must translate each statement every time the program runs. A compiler does the translation once, before running, so the executable can start executing at once. An interpreter produces no executable at all, and a compiled program is not translated while it runs.
10.

Hard[2 marks]

Which statement about compiled programs is correct?
Show answer and explanation

Answer: B · Worked explanation

An executable contains machine code for one type of processor, so it must be compiled again for another type. It does not need the compiler once it exists, because translation was done beforehand. Compilers work on high-level source code, and assemblers handle assembly language.

Keep going

Next topicA2.1 Network fundamentalsPrevious topicA1.3 Operating and control systems

More in A1 · Computer fundamentals

  1. A1.1Computer hardware and operationNotes · 10 questions
  2. A1.2Data representation and logicNotes · 10 questions
  3. A1.3Operating and control systemsNotes · 10 questions
  4. A1.4TranslationNotes · 10 questions· HL only

All IB Computer Science topics →

Draft: written by Scribe and checked automatically, not yet by a subject reviewer.

Practice questions are original, written by Scribe and checked automatically for correctness.

Topic codes follow the official numbering. Not endorsed by IB Diploma Programme or any exam board.

On this page

0/5 read

  1. 1Processors run only machine code, so programs need translating
  2. 2An assembler converts assembly language into machine code
  3. 3Compilers translate first and interpreters translate as they run
  4. 4Compilation passes through six stages, from tokens to machine code
  5. 5The best translation method depends on the situation
  6. Check your recall
  7. Practice: 10 questions
All coursesScribeHow it worksPricingPrivacyTerms

Notes and questions are written by Scribe in our own words. Topic codes follow the official course numbering so you can find your place. Not produced or endorsed by the IB, College Board, AQA, OCR, Pearson Edexcel or any exam board.

© 2026 Scribe