← GCSE Computer Science · Eduqas · GCSE Computer Science revision
⭐ 0
Eduqas GCSE Computer Science · 7, 9, 10 Languages, translators and IDEs
Mini-Lesson

Languages, translators and IDEs

4 missions. Guess, learn, then check. Your place is saved.

  1. Mission 1Why write a 1999 hit game almost entirely in assembly?
  2. Mission 2Why do some languages show all your errors, and others just one?
  3. Mission 3How can a program tell you which line your bug is on?
  4. Mission 4It passed every test. So why did it fail for an 18-year-old?
Mission 1

Why write a 1999 hit game almost entirely in assembly?

Make a guess: Why write a 1999 hit game almost entirely in assembly?

Languages · levels of programming language

What the processor actually runs

Machine codeopcodeoperand000101000011010100100110CPUillustrative 8-bit instruction set(not a real processor)
  • A CPU can only execute machine code: instructions in binary.
  • Each instruction is a simple step, such as load a value, add, store a result or jump.
  • Each processor family has its own instruction set, so machine code for one family won't run on another.
  • Machine code and assembly language are low-level languages: they work directly with the processor's own instructions.
Languages · levels of programming language

Assembly language

Assembly to machine codeAssemblyMachine codeLDA price00010100ADD tax00110101STA total00100110assembler
  • Assembly language replaces binary with short mnemonics such as LDA (load), ADD and STA (store).
  • Each assembly instruction matches exactly one machine code instruction: a 1:1 correspondence.
  • Like machine code, it is specific to one processor family.
  • An assembler translates assembly language into machine code.
Assembly language (illustrative)
LDA price    ; load price into the processor
ADD tax      ; add tax to it
STA total    ; store the result in total
Languages · levels of programming language

High-level languages

  • High-level languages use English-like keywords and maths-style expressions.
  • One statement often becomes several machine code instructions: the line below becomes the three assembly instructions you just met.
  • They are machine independent: the same source code can be translated to run on different processor families.
  • A compiler or interpreter must translate the code before the CPU can run it.
  • Most programs are high-level: they are quicker to write, read and debug.
Eduqas pseudo-code
set total = price + tax
Quick check
?A programmer writes the line STA total. What kind of code is this?
Calculate
?An assembly program has these 3 lines: LDA price, ADD tax, STA total. How many machine code instructions will it become?
Languages · levels of programming language

Choosing a level

Levels of languageeasier for humanscloser to the hardwareHigh-leveltotal = price + taxAssemblyLDA price ADD tax STA totalMachine code0001 0100 0011 01010010 0110low-level
High-levelLow-level
Reading and writingeasier: English-likeharder: mnemonics or binary
Debuggingeasier to find and fix errorsharder
Portabilitymachine independentworks on one processor family
Hardware controlindirect, through the OSdirect control of registers and memory
Speed and memorytranslated code may be less efficientcan be very fast and compact
  • Use low-level for device drivers, embedded systems and code where speed or memory is critical.
  • Use high-level for most applications, where quick development matters more.
Quick check
?A smart thermostat has a tiny chip with very little memory, and its program must control a temperature sensor directly. Which level of language suits it best?
Mission check

?Why write a 1999 hit game almost entirely in assembly?
Mission 2

Why do some languages show all your errors, and others just one?

Make a guess: Why do some languages show all your errors, and others just one?

Languages · translators

Why translate?

TranslatorsSource codeTranslator0110 10111001 0010Machine codeCPUHigh-levelCompilerHigh-levelInterpreterAssemblyAssembler
  • The CPU can only execute machine code, so the source code that programmers write must be translated first.
  • A translator is a program that converts source code into a form the CPU can execute.
  • High-level code is translated by a compiler or an interpreter.
  • Assembly is translated by an assembler: each assembly instruction becomes one machine code instruction.
Languages · translators

Compiler or interpreter?

Compiler and interpreterCompiler8 linestranslateEXEexecutablerunInterpreterline 1translaterunline 2translaterunline 3translaterun… and so on, one line at a time, to line 8
  • A compiler translates the whole program before it runs, producing an executable file of machine code that runs without the compiler.
  • An interpreter translates one line at a time into machine code and runs it. It is needed every time the program runs.
  • Errors: a compiler gives an error report for the whole program; an interpreter stops at the first error.
Quick check
?An 8-line program has errors on lines 4 and 7. What happens when you run it with an interpreter?
Languages · translators

Choosing a translator

When each is usedInterpreterwhile developingeditrunfixCompilerfor releasereleaseEXEusers
CompilerInterpreter
Translatesthe whole program, before it runsone line at a time, as it runs
Producesan executable fileno executable file
Running speedfast: already translatedslower: translated again every run
Finding errorsreport after translating everythingstops at the error, easy to see where
After a changemust recompile the whole programjust run it again
Sharingsend the executable; source stays privateusers need the source and an interpreter
  • An interpreter is mostly used while developing and testing a program; a compiler translates the final program for release.
  • An assembler is used when a program is written in assembly, e.g. for embedded systems or device drivers.
Quick check
?A games studio is ready to release its finished game and doesn't want players to see its source code. Which translator should it use?
Languages · translators

Inside a compiler

Stages of compilationset total = price + tax1 Lexical analysistokens: set · total · = · price · + · taxsymboltable2 Syntax analysisgrammar checksyntax errors3 Semantic analysistype check4 Code generationbinary: 0110 1011 …5 Code optimisationsmaller / fastermachine code
  • Lexical analysis: comments and spaces are removed; keywords, constants and identifiers become tokens; a symbol table of variables, labels and subroutines is built.
  • Syntax analysis: tokens are checked against the grammar rules; syntax errors are reported.
  • Semantic analysis: checks the code makes sense, e.g. data types suit the operations.
  • Code generation: machine code is produced.
  • Code optimisation: the code is made faster or to use fewer resources.
Languages · translators

Types of programming error

ErrorWhat goes wrongExample
Syntacticalcode breaks the language's rules, so it won't translateouptut total
Logicalthe program runs but gives the wrong result< used instead of <=
Run-time (execution)the program crashes while runningdividing by zero
Linkinga library or subroutine the code calls can't be founda missing library file
Roundinga value is rounded, so it loses accuracy0.1 + 0.2 gives 0.30000000000000004
Truncationdigits are cut off, not rounded7.9 stored as an integer becomes 7
Quick check
?A program stores 2 ÷ 3 to 2 decimal places as 0.67. Adding three of these values gives 2.01 instead of 2. Which type of error is this?
Mission check

?Why do some languages show all your errors, and others just one?
Mission 3

How can a program tell you which line your bug is on?

Make a guess: How can a program tell you which line your bug is on?

Languages · IDEs

One program for writing, running and fixing code

An IDEIDE▶ Run1total = 02for i = 1 to 33 total = total + i4next i5print(total)run-time environmenterrorstranslator
  • An Integrated Development Environment (IDE) is software that puts tools for writing, translating, running and debugging code in one place.
  • The editor is where you write and edit code. It provides automatic line numbering, automatic colour coding of keywords and automatic formatting (indentation), so code is easier to read.
  • Statement completion suggests how to finish a statement as you type.
Languages · IDEs

Translate, run and diagnose

  • The IDE includes a translator, so you can compile or interpret your code with one click.
  • Error diagnostics report each error with a message and its line number, and highlight that line.
  • Syntax error detection marks code that breaks the language's rules, often as you type.
Calculate
?You run this program in an IDE. Which line number will the error diagnostics highlight?
Eduqas pseudo-code
set total = 0
for i = 1 to 3
    set total = total + i
nxt i
output total
Languages · IDEs

Debugging tools

DebuggingIDEStep▶ Run1total = 02for i = 1 to 33 total = total + i4next i5print(total)watchi = 2total = 1Paused at line 3red dot = breakpointstep: run one line at a time
  • A break point pauses the program at a chosen line, before that line runs.
  • Trace runs the program one line at a time, so you can follow the path it takes.
  • A variable watch shows the current value of chosen variables while the program runs.
  • A memory inspector shows the contents of the memory locations the program is using.
  • These are features of the debugger.
Calculate
?The corrected program below has a breakpoint on line 3 and a watch on total. The program pauses each time it reaches line 3. What does the watch show for total at the third pause?
Eduqas pseudo-code
set total = 0
for i = 1 to 3
    set total = total + i
next i
output total
Languages · IDEs

Building the final program

  • Libraries are collections of ready-written, tested code for use in your own programs.
  • They hold routines/subroutines and standard functions, e.g. to find the length of a string.
  • The linker joins your translated code and the library routines it uses into one executable file.
  • The loader copies the executable from storage into RAM so it can run.
  • Code optimisation makes the translated code faster or use less memory.
Quick check
?Your program calls a sorting routine from a library. Which tool joins that routine to your translated code to make one executable?
Quick check
?A classmate's long program has no indentation and is hard to follow. Which IDE feature helps most?
Mission check

?How can a program tell you which line your bug is on?
Mission 4

It passed every test. So why did it fail for an 18-year-old?

Make a guess: It passed every test. So why did it fail for an 18-year-old?

Programming · testing

Why test?

  • Testing checks that a program works as intended and meets its requirements.
  • It finds errors so they can be fixed before users meet them.
  • A program can run without crashing and still give wrong results.
  • Passing a few easy tests proves little: choose test data that could expose errors.
Programming · testing

Normal, edge and wrong data

Test datavalid: 1 to 10−1234678912015101115normalerroneousboundaryboundarytenerroneous

For a program that accepts whole numbers from 1 to 10:

  • Typical data: sensible values that should be accepted, e.g. 5.
  • Extreme data: the smallest and largest acceptable values, 1 and 10.
  • Erroneous data: data that should be rejected, e.g. ten, −3 or 3.14.
Calculate
?The rule is "adult ticket for 18 and over". Tests with ages 10, 30 and 50 all gave the right ticket. Which single age would show the error?
Eduqas pseudo-code
input age
if age > 18
  output "Adult ticket"
else
  output "Child ticket"
end if
Quick check
?A program accepts whole numbers from 1 to 10. A tester types the word ten. What type of test data is this?
Programming · testing

Types of error

  • A syntax error breaks the rules of the language, e.g. a missing bracket. The program cannot be translated or run.
  • A logic error lets the program run, but it gives the wrong or unexpected result, e.g. > where ≥ was needed.
  • A runtime error happens while the program runs and makes it crash, e.g. dividing by zero or using an index past the end of an array. Eduqas calls this a run-time or execution error.
  • Testing with good test data is how you find logic errors.
Quick check
?A program should output the average of three marks, 60, 70 and 80. It runs, but outputs 156.67 because the code says a + b + c / 3. What kind of error is this?
Programming · testing

Test plans

Test planTest planTestDataTypeExpectedActual15NormalAcceptedAccepted210BoundaryAcceptedRejected311InvalidRejectedRejected4tenErroneousRejectedRejectedTest 2: expected ≠ actual
  • A test plan lists each test before it is run: what it tests, the test data, its type and the expected result.
  • After running, record the actual result. If they differ, fix the code and test again.
TestDataTypeExpectedActual
15TypicalAcceptedAccepted
210ExtremeAcceptedRejected
311ErroneousRejectedRejected
4tenErroneousRejectedRejected
  • Test 2 failed, so the range check needs fixing.
Programming · testing

Code that is easy to maintain

  • Other people (and you, later) must be able to read and change code. This is maintainability.
  • Self-documenting identifiers: totalScore, not t.
  • Annotation (comments) explain what each part of the code does.
  • Indentation shows which lines belong inside loops, selection and subprograms.
  • White space and a clear layout split code into readable blocks.
  • Subroutines with well-defined interfaces break code into named, reusable parts.
Mission check

?It passed every test. So why did it fail for an 18-year-old?
Recap

Big ideas

  • The CPU only runs machine code (binary); assembly uses mnemonics with a 1:1 match to machine code. Both are low-level and tied to one processor family.
  • High-level languages are easier to write, read and debug and are machine independent, but must be translated.
  • Low-level suits device drivers, embedded systems and speed-critical code; high-level suits most applications.
  • Source code must be translated before the CPU can run it: a compiler translates the whole program into an executable; an interpreter translates and runs it line by line.
  • Interpreters suit development and testing; compilers suit the final program; assemblers translate assembly language.
  • A compiler works in stages (lexical, syntax and semantic analysis, code generation, optimisation), and errors range from syntax to rounding and truncation.
  • An IDE puts an editor, a translator, debugging tools and error diagnostics in one program.
  • Editor features such as line numbers, colour coding and automatic formatting and statement completion make code easier to write and read.
  • Breakpoints, trace and variable watches help you find logic errors while the program runs.
  • Choose test data of every kind: normal, at the edges of the range, and data that should be rejected (typical, extreme, erroneous).
  • Syntax errors stop a program running; logic errors give wrong results; runtime errors crash it while it runs.
  • Meaningful names, comments, indentation and subprograms make code easy to maintain.
🏆

Mini-lesson complete!

⭐⭐⭐

You've worked through Languages, translators and IDEs for Eduqas GCSE Computer Science. 🎉

  1. Mission 1Why write a 1999 hit game almost entirely in assembly?
  2. Mission 2Why do some languages show all your errors, and others just one?
  3. Mission 3How can a program tell you which line your bug is on?
  4. Mission 4It passed every test. So why did it fail for an 18-year-old?

Your stars: 0 / 0

Next: more GCSE Computer Science · Eduqas lessons and games on the GCSE Computer Science · Eduqas page.

📣 Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

→ Back to GCSE Computer Science · Eduqas

Specification points and sources for this lesson are listed at the bottom of the page.

Sources (7)

The specification points and sources behind this lesson.

  1. 1 Eduqas GCSE CS spec 2020, section 7; teacher guidance section 7
  2. 2 Eduqas GCSE CS spec 2020, section 10; teacher guidance section 10
  3. 3 Eduqas GCSE CS spec 2020, section 9; teacher guidance section 9
  4. 4 Eduqas GCSE CS spec, Component 1 section 10, Component 2 Implementation and Testing; Eduqas guidance for teaching (typical, extreme, erroneous example)
  5. 5 Chris Sawyer (the game's creator), official site: FAQ "Chris Sawyer Software Development", Q "What language was RollerCoaster Tycoon programmed in?" ("99% written in x86 assembler/machine code … with a small amount of C code used to interface to MS Windows and DirectX"), https://chrissawyergames.com/faq3.htm; release "early in 1999": https://chrissawyergames.com/info.htm
  6. 6 Atari (publisher of the RollerCoaster Tycoon series), "Interview with RollerCoaster Tycoon's creator Chris Sawyer", Atari's own Medium publication Atari Club, Carly Francis, 27 March 2024; Sawyer's own answer to "Why did you write RollerCoaster Tycoon in assembly language … rather than a high level language like C?", https://medium.com/atari-club/interview-with-rollercoaster-tycoons-creator-chris-sawyer-684a0efb0f13
  7. 7 PCGamesN, "RollerCoaster Tycoon: the best-optimised game of all time?", https://www.pcgamesn.com/rollercoaster-tycoon/code-chris-sawyer