O Level Computer Science 2210 · Area 1 · Computer systems

Translators, programming languages and IDEs

The processor understands only machine code, so every program you write has to be translated, and this page covers the languages and the translators that do it. You need the advantages and disadvantages of high-level and low-level languages, how assembly language and mnemonics fit in, how a compiler and an interpreter each translate and report errors, and what an IDE gives a programmer. Marks are lost when students describe a compiler as working line by line, or answer an IDE question with 'it helps you write code' instead of naming its functions.

Not started

Syllabus coverage

  • Explain what is meant by a high-level language and a low-level language, including the advantages and disadvantages of each
  • Understand the advantages and disadvantages in terms of ease of reading and writing code, ease of debugging, machine independence and direct manipulation of the hardware
  • Understand that assembly language is a form of low-level language that uses mnemonics, and that an assembler is needed to translate an assembly language program into machine code
  • Describe the operation of a compiler and an interpreter, including how high-level language is translated by each and how errors are reported
  • Explain the advantages and disadvantages of a compiler and an interpreter
  • Explain the role of an IDE in writing program code and the common functions IDEs provide

Part of the O Level Computer Science syllabus 2210.

Translators, and the IDE around themA compiler translates the whole program before it runs; an interpreter translates and runs a statement at a time.An assembler is the translator for assembly language, which is a low-level language.high-level source codePython, Java, VBcompilerinterpretermachine codeA compiler translates the whole program once and reports all errors at the end.An interpreter translates one statement at a time and stops at the first error.An assembler translates mnemonics into machine code, one instruction for one instruction.Inside an IDEeditor with syntax colourerror diagnosticsrun and debug toolsauto-completion
A high-level language program on the left passing through either a compiler, which produces an executable file, or an interpreter, which runs the code line by line, with both routes ending in machine code, and an assembler shown separately translating mnemonics into machine code.

High-level languages

A high-level language is written in a form close to English, using meaningful names and structures such as loops, conditions and procedures. One statement may do the work of many machine code instructions, and the programmer does not have to think about which register holds which value or where in memory a variable lives.

The advantages follow from that distance from the hardware. High-level code is easy to read and write, because it reflects the problem being solved rather than the design of the processor. It is easy to debug, because the code is easier to follow and the translator can report an error together with the line it is on. It is machine independent: the same source code can be translated to run on different types of processor, because it does not refer to any particular processor's instructions.

The disadvantage is the mirror image. The programmer has no direct manipulation of the hardware, so a specific processor feature cannot be used, and the translated code may not make the most efficient use of memory or processing time. High-level languages are the normal choice for applications, websites and most software written today.

High-level does not mean better, it means further from the hardware: easier for people, less control for the programmer.

Low-level languages

A low-level language is written in a form close to the hardware. It uses the processor's own instructions and memory addresses, so the programmer works at the level of the machine rather than the level of the problem. Assembly language, covered below, is the readable form of low-level language, and machine code is the binary form the processor actually executes.

The advantage is direct manipulation of the hardware. The programmer can choose exactly which instruction is used, which register holds a value and which memory address is read, so code can be written to run very fast or to fit into a very small amount of memory. That is why low-level languages survive in device drivers, in the routines of an operating system where speed and control matter, and in embedded systems with tiny amounts of memory.

The disadvantages are that low-level code is hard to read and write, because it looks nothing like the problem, and hard to debug, because mistakes are easy to make and difficult to trace. It is also machine dependent: a program written for one type of processor will not run on another, so it has to be rewritten for each family of processor.

Never answer 'low-level languages are worse'. Say what they buy, which is direct control of the hardware and code that can be faster and smaller, and say what they cost, which is readability, debugging and portability.

Comparing high-level and low-level languages

The four headings the syllabus names are ease of reading and writing code, ease of debugging, machine independence and direct manipulation of the hardware. Learn one sentence for each heading and you can answer any version of the question.

Notice how the advantages and disadvantages are two sides of the same property. A high-level language is easy to read because it is far from the hardware, and that same distance is why it cannot control the hardware directly. A low-level language gives control because it is close to the hardware, and that closeness is why it is hard to read.

High-level languageLow-level language
Reading and writing codeEasy: close to English, uses meaningful namesHard: close to the hardware, uses mnemonics or binary
DebuggingEasier: code is readable and errors can be reported with a line numberHarder: mistakes are easy to make and difficult to trace
Machine independenceMachine independent: can be translated to run on different processorsMachine dependent: written for one type of processor
Direct manipulation of the hardwareNot possible: the programmer cannot use specific processor instructionsPossible: the programmer works directly with the processor's instructions, registers and addresses
Where you meet itApplications, websites, most software written todayDevice drivers, operating system routines, embedded systems where speed or size matters

Machine code, assembly language and mnemonics

The processor executes only machine code, which is binary instructions made up of an opcode saying what to do and an operand saying what to do it to. Writing in binary is slow, tiring and full of errors, and a single wrong bit changes the instruction completely.

Assembly language was created to make low-level programming bearable. It is still a low-level language, but it replaces binary opcodes with mnemonics: short letter codes such as `LDA` for load, `ADD` for add and `STO` for store. It also replaces memory addresses with names, so the programmer can write `LDA total` instead of a binary address.

Each mnemonic corresponds to exactly one machine code instruction. There is no one-to-many translation and no hidden work: what the programmer writes is what the processor runs, instruction for instruction. That is why assembly language still counts as low-level, even though it contains letters rather than only 1s and 0s. The programmer still has to think about registers, memory addresses and the order in which the processor does things.

Assembly languageMeaningMachine code equivalent
LDA totalLoad the value at 'total' into the accumulatorOne binary instruction with the load opcode
ADD priceAdd the value at 'price' to the accumulatorOne binary instruction with the add opcode
STO totalStore the accumulator back into 'total'One binary instruction with the store opcode
Mnemonics are letter codes standing in for binary opcodes, not English. ADD is not the English word add; it is a label for one machine code instruction.

The assembler

The processor does not understand mnemonics, so an assembly language program cannot run as it is written. An assembler is the translator that converts it into machine code, replacing each mnemonic with its binary opcode and each named address with the actual address.

The translation is close to one assembly language instruction for one machine code instruction, so an assembler is much simpler than a compiler. It does not restructure the program or optimise it; it substitutes codes and addresses and produces a machine code program the processor can execute.

The three translators are easy to keep apart if you match each to its source: an assembler translates assembly language into machine code, a compiler translates a high-level language into machine code, and an interpreter translates a high-level language line by line as it runs.

Assembler takes assembly language to machine code. Compiler takes high-level language to machine code. Interpreter takes high-level language line by line, while running it.

How a compiler works

A compiler translates the whole program at once, before any of it is executed, and produces an executable file. The programmer runs the compiler, gets the executable, and can then run that executable as many times as they like without the compiler being involved again.

If the compiler finds errors it produces an error report for the whole program, listing the errors it has found and the line each one is on. No executable file is produced until those errors are fixed. Because the report covers the whole program, the programmer can see several errors at once and fix them together.

The advantages follow from translating everything in advance. Execution is fast, because the translation is already done by the time the program runs. The executable can be given to users who do not have the compiler or the source code, which also means the source code can be kept private. The disadvantages are that the compiler must be run again after every change, which slows development down, that translating a large program can take a long time, and that the executable is machine dependent, so a different version is needed for a different type of processor.

The two phrases that earn the marks: 'translates the whole program at once before executing it' and 'produces an executable file'. Add the error report as a separate point.

How an interpreter works

An interpreter translates and executes the code line by line. No separate executable file is produced: the interpreter reads a line, translates it, runs it, then moves on to the next line, and it must be present every time the program is run.

If it finds an error it stops execution at that point and reports the error. That has two consequences the examiner looks for: the lines before the error have already run, and any errors further down the program have not been found yet.

The advantages are the mirror image of the compiler's. An interpreter is useful while a program is being written, because the programmer can run part of the program and see the result immediately without waiting for the whole thing to be translated. An error stops the program at the line that caused it, which makes that error easier to locate. Its disadvantages are that the same line is translated again every time it is executed, so the program runs more slowly, and that the interpreter must be installed on the computer for the program to run at all.

An interpreter stops at the first error. It does not produce a report for the whole program, and it does not produce an executable file.

Compiler or interpreter: the comparison

The comparison is best learned as pairs, because every point about one has a matching point about the other. A compiler translates the whole program at once, before execution; an interpreter translates and executes line by line. A compiler produces an executable file; an interpreter produces none and must be present to run the program. A compiler reports errors for the whole program; an interpreter stops at the first error it meets.

The speeds also run in opposite directions. A compiled program runs fast but takes longer to develop, because the whole program must be recompiled after every change. An interpreted program runs slowly but develops quickly, because part of it can be run at once.

CompilerInterpreter
How it translatesTranslates the whole program at once, before it is executedTranslates and executes the code line by line
Executable fileProduces an executable file that can be run on its ownProduces no executable file; the interpreter must be present to run the program
How errors are reportedGives an error report for the whole program, listing the errors foundStops execution when an error is found and reports that error
Speed when the program runsFast, because the translation is already doneSlower, because each line is translated every time it is executed
Speed of developmentSlower, because the whole program must be recompiled after every changeFaster, because part of the program can be run immediately
Typical useTranslating the final programDeveloping and testing a program
Both translators turn a high-level language into something the computer can run. The difference is timing: a compiler translates the whole program before executing it, an interpreter translates and executes line by line.

Which translator is used when

In practice both are used on the same project, at different times. An interpreter is mostly used when a program is being developed, because it gives feedback line by line while the code is being written and stops at the exact line where something goes wrong. A compiler is used to translate the final program, because the finished version should run as fast as possible and be ready to hand to users who have no development software installed.

  • Developing: interpreter, for immediate feedback and an error at the line that caused it.
  • Finished program: compiler, for speed and for an executable that runs without the translator.
  • Teaching or trying a few lines: interpreter, because no separate build step is needed.
  • Software for sale: compiler, because the executable runs on its own and the source code can stay private.

Integrated development environments (IDEs)

An integrated development environment (IDE) is a single piece of application software that provides everything a programmer needs to write, test and translate a program. Its role is to bring the separate tools of program development together in one place, so the programmer does not have to keep switching between a text editor, a translator and a testing tool.

The code editor is where the code is typed. It is more than a plain text editor: it numbers the lines, colours the different parts of the code so that keywords and strings stand out, and indents automatically. Error diagnostics means the IDE reports errors as the programmer works, marking the line where the problem is and explaining what the translator objected to, which turns debugging from guesswork into reading a message.

Auto-completion means the IDE suggests how a word or line might finish as it is typed and offers a list of the available options, so the programmer types less and makes fewer typing mistakes. Auto-correction means the IDE corrects or completes obvious mistakes, such as closing a bracket that was left open or fixing the spelling of a keyword. Prettyprint means the IDE lays the code out neatly, with consistent indentation and spacing, so that the structure of loops and conditions can be seen at a glance.

The run-time environment means the IDE can run the program and show the output, and often step through it line by line to watch the values in variables change. The translators built into the IDE, which may include a compiler, an interpreter and an assembler, mean the program can be translated without leaving the IDE.

Function of an IDEWhat it gives the programmer
Code editorA place to type the code, with line numbers, colour-coded keywords and automatic indentation
Run-time environmentThe ability to run the program and see its output without leaving the IDE, and often to step through it line by line
TranslatorsA compiler, interpreter or assembler built in, so the program can be translated from inside the IDE
Error diagnosticsReports of errors as the programmer works, showing the line the error is on and what is wrong
Auto-completionSuggestions that finish a word or line as it is typed, and lists of available options
Auto-correctionAutomatic correction of obvious mistakes, such as a missing closing bracket or a misspelled keyword
PrettyprintAutomatic layout of the code with consistent indentation and spacing, so its structure is easy to see
Do not answer an IDE question with 'it helps you write code'. Name the functions: code editor, error diagnostics, auto-completion, auto-correction, prettyprint, run-time environment and built-in translators.

Key terms you must be able to define

High-level language
A programming language written in a form close to English that is easy to read and debug and is machine independent, but gives the programmer no direct manipulation of the hardware.
Low-level language
A programming language written in a form close to the hardware that allows direct manipulation of the hardware and can be fast and compact, but is hard to read and debug and is machine dependent.
Machine code
The binary instructions that the processor executes, each made up of an opcode and an operand. It is the only language the hardware understands.
Opcode
The part of a machine code instruction that says which operation to carry out.
Operand
The part of a machine code instruction that says what the operation is to be carried out on, such as a value or an address.
Assembly language
A low-level language that uses mnemonics in place of binary opcodes and names in place of memory addresses, with one mnemonic for each machine code instruction.
Mnemonic
A short letter code used in assembly language in place of a binary opcode, such as LDA for load, ADD for add and STO for store.
Assembler
The translator that converts an assembly language program into machine code.
Compiler
A translator that translates the whole high-level program at once before it is executed, producing an executable file and giving an error report for the whole program if errors are found.
Interpreter
A translator that translates and executes a high-level program line by line, stopping and reporting an error when one is found.
Executable file
The machine code file produced by a compiler, which can be run on its own without the compiler or the original source code.
Integrated development environment (IDE)
A single piece of software that provides the tools needed to write, test and translate a program, including a code editor, a run-time environment, translators, error diagnostics, auto-completion, auto-correction and prettyprint.
Prettyprint
An IDE function that lays out code with consistent indentation and spacing so that its structure is easy to read.

In context

2210 sets its questions inside systems a student already uses - a school network, a phone, a supermarket till, a vending machine, a website. These show how the theory is applied to a context you have not seen before, then you answer for the system you are given.

In a software company

A programmer writes the code in an IDE, using auto-completion to type less and error diagnostics to spot mistakes as she goes. While she is developing, she runs the program with an interpreter so she can see each line work and find the line that fails. When the program is finished, she compiles it, because the compiler produces a fast executable file that can be sent to users who have no programming software installed at all.

In a games console

The finished game is compiled, because a compiled executable runs far faster than a program being translated line by line, and speed is the whole point of a game. The compiler also keeps the source code out of the hands of anyone who buys the game, since only the executable is shipped.

In a device driver

The software that drives a network card is written in assembly language, because it has to place values in particular registers and read particular memory addresses. Each mnemonic maps onto one machine code instruction, so the programmer keeps complete control, but the driver has to be rewritten for a different type of processor.

In a classroom

A student learning to program writes a short program and runs it with an interpreter. She gets an error message naming the line, fixes it, and runs the program again within seconds. If she had to compile the whole program each time she would wait longer for each attempt and might not connect the error message with the line that caused it.

In a small software team

The team keeps one copy of the source code in a high-level language. Machines with different processors run the same source, because a compiler exists for each type of processor. This is machine independence in practice: the code is written once and translated for each target.

In an embedded system

The controller in a washing machine has a few kilobytes of memory. Its program is written in assembly language so that it fits and runs quickly, and an assembler turns it into the machine code that is burnt into the controller's ROM.

Flashcards

Click a card to flip it. Mark honestly — the tracker uses this.

Q1Give two advantages of a high-level language over a low-level language.
It is easier to read and write, it is easier to debug, and it is machine independent. A low-level language gives direct manipulation of the hardware but is hard to read and debug and is machine dependent.
Q2Give one advantage and one disadvantage of a low-level language.
Advantage: direct manipulation of the hardware, so code can be very fast and use very little memory. Disadvantage: it is hard to read and debug, and it is machine dependent.
Q3What is machine code?
The binary instructions the processor executes, each made up of an opcode and an operand. It is the only language the hardware understands.
Q4What is the difference between assembly language and machine code?
Machine code is binary and is the only language the processor executes. Assembly language is the same instructions written using mnemonics, and an assembler translates it into machine code.
Q5What is a mnemonic?
A short letter code used in assembly language in place of a binary opcode, such as LDA for load, ADD for add and STO for store. Each mnemonic is one machine code instruction.
Q6Why is an assembler needed?
Because the processor does not understand mnemonics. The assembler translates the assembly language program into machine code, replacing each mnemonic with its opcode and each named address with the actual address.
Q7How does a compiler translate a program, and what does it produce?
It translates the whole program at once before it is executed, produces an executable file, and gives an error report for the whole program if errors are detected.
Q8How does an interpreter translate a program, and how does it report errors?
It translates and executes the code line by line, and it stops execution when an error is found, reporting that error.
Q9Give one advantage and one disadvantage of a compiler.
Advantage: the compiled program runs fast and the executable can be used without the compiler or the source code. Disadvantage: the whole program must be recompiled after every change, and the executable is machine dependent.
Q10Give one advantage and one disadvantage of an interpreter.
Advantage: useful during development, because the program can be run immediately and an error stops at the line that caused it. Disadvantage: the program runs more slowly, because each line is translated every time it is executed.
Q11Which translator is used while developing a program, and which for the final version?
An interpreter is mostly used while developing, for line-by-line feedback. A compiler is used to translate the final program, for speed and for an executable that runs on its own.
Q12Name four functions an IDE provides.
Any four of: code editor, run-time environment, translators, error diagnostics, auto-completion, auto-correction, prettyprint.
Q13What is prettyprint?
An IDE function that lays out code with consistent indentation and spacing so that its structure, such as loops and conditions, is easy to see.
0 of 13 marked as known

Exam-style questions

7 questions, 25 marks. Write your answer and press Mark my answer — it is marked against the scheme and tells you which points you made and what would gain the next mark. You can still reveal the scheme and mark it yourself instead.

StateAO11 mark
State the type of translator that converts an assembly language program into machine code.

Mark scheme — tick each point you actually made

Examiner tip: One word. Do not write 'compiler' because assembly language is being translated; a compiler translates a high-level language.
ExplainAO12 marks
Explain why assembly language is described as a low-level language.

Mark scheme — tick each point you actually made

Examiner tip: Do not be misled by the words in the mnemonics. ADD and STO are letter codes standing in for binary opcodes, not English, so the language is still low-level.
CompareAO24 marks
Compare a compiler and an interpreter. Your answer should include how each translates the code and how each reports errors.

Mark scheme — tick each point you actually made

Examiner tip: A comparison needs both sides. Every point you make about the compiler should be matched with what the interpreter does differently, or you are describing rather than comparing.
ExplainAO23 marks
A programmer writes a new program. Explain why she uses an interpreter while she is developing the program, but a compiler to produce the version she gives to users.

Mark scheme — tick each point you actually made

Examiner tip: The two halves of this answer are speed of development and speed of the finished program. Say which is which, and do not forget that the compiled version runs without the development software.
DescribeAO24 marks
Describe two advantages and two disadvantages of using a low-level language rather than a high-level language.

Mark scheme — tick each point you actually made

Examiner tip: Answer with four separate points and label them advantage or disadvantage. Each needs its reason attached, not just a claim.
ExplainAO25 marks
Explain the role of an integrated development environment (IDE) in writing program code, and describe three functions that an IDE provides.

Mark scheme — tick each point you actually made

Examiner tip: Give the role first, then the functions. Each function needs a sentence saying what it gives the programmer, because naming the function on its own is not enough for the mark.
EvaluateAO36 marks
A small team is writing a program that will be sold to schools. The program must run on computers with two different types of processor, and the team wants to keep the source code private. Evaluate whether the team should write the program in a high-level or a low-level language.

Mark scheme — tick each point you actually made

Examiner tip: This is an evaluation question, so you must reach a decision. Weigh the two languages against the two constraints in the question, portability and privacy, and finish with a clear judgement that says why.

Exam technique for this topic

  • For compiler versus interpreter, the two phrases that earn marks are 'translates the whole program at once before executing it' and 'translates and executes line by line'. Add what happens when an error is found, because that is a separate mark.
  • Keep the three translators matched to their sources: assembler from assembly language, compiler from high-level language to an executable, interpreter from high-level language line by line. Mixing them up loses marks in every part of the question.
  • For an advantages and disadvantages question, always attach a reason. 'It is faster' is not a mark, but 'the programmer can use specific processor instructions, so the code runs faster' is.
  • When asked about an IDE, give its role in one sentence and then name at least three functions with a sentence each: code editor, error diagnostics, auto-completion, auto-correction, prettyprint, run-time environment, translators.
  • Remember the machine-independence point. High-level code is machine independent, a compiled executable is machine dependent, and assembly language is machine dependent. This one distinction is examined repeatedly.

Why students lose marks here

A student wroteA student wrote: 'The compiler translates the program line by line and stops when it finds an error.'
Why it loses marksThat is the description of an interpreter. A compiler translates the whole program before any of it is executed, and it produces an error report for the whole program rather than stopping at the first problem.
The answer that scoresA compiler translates the whole program at once before executing it, and produces an executable file. If errors are detected it produces an error report for the whole code, so the programmer can fix several errors at once. An interpreter translates and executes the code line by line and stops execution when it finds an error.
A student wroteA student wrote: 'Assembly language must be a high-level language because it uses words such as ADD and STO.'
Why it loses marksMnemonics are short letter codes that stand for binary opcodes, not English words. Each mnemonic corresponds to exactly one machine code instruction, so assembly language is still close to the hardware: it is a low-level language, and the programmer still has to manage registers and memory addresses.
The answer that scoresAssembly language is a low-level language that uses mnemonics in place of binary opcodes and names in place of memory addresses. Because the processor does not understand mnemonics, an assembler is needed to translate the assembly language program into machine code.
A student wroteA student wrote: 'An interpreter is better than a compiler because it reports errors sooner.'
Why it loses marksThe interpreter does stop at the first error, but that is an advantage during development rather than a reason to prefer it overall. A compiled program runs faster, and the executable can be given to users who do not have the interpreter installed, which is why a compiler is used to translate the final program.
The answer that scoresAn interpreter translates and executes line by line, so it stops at the first error and reports it, which is useful while a program is being developed. A compiler translates the whole program at once, reports all the errors it finds, and produces an executable file that runs fast and can be used on a computer with no development software. An interpreter is mostly used when developing a program and a compiler is used to translate the final program.
A student wroteA student wrote: 'A high-level language is machine independent, so the same executable runs on any computer.'
Why it loses marksIt is the source code that is machine independent. The executable produced by a compiler is machine code for one type of processor, so a version must be compiled for each type. Only the source is portable.
The answer that scoresHigh-level source code is machine independent, because it does not refer to any particular processor's instructions, so it can be translated for different processors. The executable file produced by a compiler is machine dependent, so a different version is needed for each type of processor.
A student wroteA student wrote: 'An IDE is a programming language used to write programs.'
Why it loses marksAn IDE is not a language. It is application software that provides the tools for writing and testing a program: a code editor, translators, error diagnostics, auto-completion, auto-correction, prettyprint and a run-time environment.
The answer that scoresAn IDE is a single piece of application software that brings the tools of program development together. It provides a code editor, built-in translators, error diagnostics, auto-completion, auto-correction, prettyprint and a run-time environment, so the programmer can write, translate and test a program without switching between separate tools.

Where this fits in O Level Computer Science 2210

This page is one topic of Cambridge O Level Computer Science 2210. O Level Computer Science 2210 is the course home: every area and every topic in Cambridge's own order, the papers you sit and what each one tests, and the exam-practice tools. The full topic list, with each topic linked to its revision page, is on the O Level Computer Science 2210 syllabus page.