Ch 2 · 4.2 Programming Languages, Translators and IDEs · O Level Computer Science 2210
Topic 2 of 2 in Software — O Level Computer Science 2210 — 49 lessons.
Introduction
A CPU only understands machine code: long strings of binary. Programmers write in languages that people can read, so the code must be translated. This lesson compares languages, the three kinds of translator, and the tools programmers use. (Syllabus section 4.2.)
Key ideas — High-level and low-level languages
A high-level language (Python, Java, Visual Basic) uses English-like keywords and maths-like notation. A low-level language is close to the hardware: machine code (binary) or assembly language.
🧑🏫 Teacher's explanation
Think of programming languages like instructions for building furniture. A high-level language is like a manual written in plain English: "Attach the leg to the tabletop using four screws." It is easy for a human to read and understand, but the carpenter (the computer) needs a translator to turn those English words into the specific physical movements required.
📖 Definitions
🔍 Worked example — Easy
Identify whether the following characteristics belong to a High-Level Language (HLL) or a Low-Level Language (LLL):
🔍 Worked example — Standard
A programmer is writing a device driver for a new type of specialized sensor. Should they use a high-level language or a low-level language? Justify your answer.
🔍 Worked example — Exam-style
Compare the execution of a program translated by a Compiler versus an Interpreter.
⚠️ Common errors
🧠 Quick check 1
🧠 Quick check 2
🎯 Exam question
(a) State one advantage and one disadvantage of using a compiler. [2] (b) Describe the main difference between how a compiler and an interpreter translate high-level language code. [2] [4 marks]
Key ideas — Assembly language
Assembly language is a low-level language that uses mnemonics: short words standing for machine-code instructions, e.g. LDA (load), ADD, STO (store), JMP (jump). Each mnemonic usually corresponds to one machine-code instruction.
🧑🏫 Teacher's explanation
Imagine you are trying to give instructions to a robot that only understands a very complex, long string of binary numbers like 01101011. It would be incredibly difficult and slow for a human to write an entire program using only those numbers. Instead, we use 'mnemonics'—short, easy-to-remember words like ADD or MOV—to represent those binary patterns. This is Assembly Language.
📖 Definitions
🔍 Worked example — Easy
A programmer uses the mnemonic LDA 50 to represent the machine code instruction 0001\ 0011\ 0010. If the assembler converts the mnemonic LDA to 0001 and the address 50 to 0011\ 0010, what is the resulting 16-bit machine code instruction?
🔍 Worked example — Standard
Compare the following two instruction sets. Instruction A uses mnemonics: ADD R1, R2. Instruction B uses machine code: 0010\ 0001\ 0010. Which is a low-level language and why?
🔍 Worked example — Exam-style
A programmer writes a program in assembly language. The assembler encounters the mnemonic SUB which corresponds to 1010 and the register R1 which corresponds to 0001. The instruction is SUB R1. Convert this to a 8-bit machine code instruction.
⚠️ Common errors
🧠 Quick check 1
🧠 Quick check 2
🎯 Exam question
Key ideas — Compilers and interpreters
High-level code is translated by a compiler or an interpreter.
🧑🏫 Teacher's explanation
Imagine you are reading a book written in a foreign language. An interpreter is like a live translator standing next to you, translating every sentence as you read it. If they hit a sentence they don't understand, they stop immediately and tell you. A compiler, however, is like a professional translator who takes the entire book, translates it all into your language, and hands you a brand new version of the book. You can then read that new version very quickly without the translator ever being present again.
📖 Definitions
🔍 Worked example — Easy
A programmer is writing a new application and wants to test small sections of code immediately as they write them. Should they use a compiler or an interpreter?
🔍 Worked example — Standard
A software company wants to sell a high-performance video game to millions of users. They want the users to run the game without needing the original source code and want it to run as fast as possible. Which translator should they use for the final product?
🔍 Worked example — Exam-style
A program contains the following three lines of code:
⚠️ Common errors
🧠 Quick check 1
🧠 Quick check 2
🎯 Exam question
(a) State one advantage of using an interpreter instead of a compiler during the development stage. [1] (b) The programmer decides to distribute the final version of the software. Explain why they would prefer to provide a compiled version rather than an interpreted version. [2] [3 marks]
Key ideas — Integrated development environments (IDEs)
An IDE is software that provides tools to help programmers write, test and debug code in one place. Common functions:
🧑🏫 Teacher's explanation
Imagine you are a professional chef. You could work in a tiny, empty kitchen with just a knife and a stove (this is like writing code in a basic text editor). It is possible, but very slow and difficult. Now, imagine a modern, high-tech professional kitchen. It has specialized stations for chopping, measuring, and baking, an assistant who tells you if you've forgotten salt, and a timer that beeps when things are ready. This professional kitchen is an Integrated Development Environment (IDE).\n\nAn IDE is essentially a 'super-powered' text editor. Instead of having one program to write code, another to translate it, and another to find mistakes, the IDE bundles all these tools into a single interface. This allows a programmer to stay focused on the logic of the program rather than the mechanics of the software tools.
📖 Definitions
🔍 Worked example — Easy
A programmer is using an IDE. They have written a loop that never ends (an infinite loop). Which IDE function would be most useful to stop the program and inspect the variables at that exact moment?
🔍 Worked example — Standard
Compare the error reporting behavior of a Compiler versus an Interpreter when a syntax error is found on line 5 of a 10-line program.
🔍 Worked example — Exam-style
A developer wants to ensure their code is highly readable by using consistent indentation and color-coded keywords. Which IDE function should they rely on?
⚠️ Common errors
🧠 Quick check 1
🧠 Quick check 2
🎯 Exam question
Worked example
A developer is writing a new app. Explain why she might use an interpreter while writing it but a compiler before releasing it.
🔍 Worked example — Easy
A programmer is using an interpreter to write a loop. The loop contains a syntax error on the 5th line. Describe the behavior of the interpreter.
🔍 Worked example — Standard
Compare the execution speed of a program translated by a compiler versus a program translated by an interpreter.
🔍 Worked example — Exam-style
A developer wants to release a commercial game to millions of users. Explain why they would distribute a compiled executable rather than the source code with an interpreter.
⚠️ Common errors
Common mistakes
Practice
Answers: (1) High-level: easier to read and write; easier to debug; machine independent. Low-level: direct control of hardware / fast, efficient code. (2) A short code word representing a machine-code instruction (e.g. ADD); an assembler. (3) Any two: a compiler translates the whole program at once, an interpreter line by line; a compiler produces an executable file, an interpreter does not; a compiler reports all errors at the end, an interpreter stops at the first error. (4) Any four: code editor, run-time environment, translators, error diagnostics, auto-completion, auto-correction, prettyprint.