High-level and low-level languages
- High-level languages, such as Python, Java and C#, use English-like keywords. They are easier to write, read and debug, and they are portable: the same code can run on different types of processor. They must be translated into machine code.
- Low-level languages are close to the hardware. Machine code is the binary instructions the CPU runs directly. Assembly language uses short mnemonics, such as ADD or LDA, one for each machine code instruction.
- Low-level code gives direct control of the hardware and can be very fast and small, which suits embedded systems. But it is hard to write, and it only works on one type of processor.
Translators
- A compiler translates the whole program into machine code in one go, making an executable file. It reports all the errors at the end. The executable runs quickly without the compiler, and the source code doesn't need to be shared.
- An interpreter translates and runs the program one line at a time. It stops at the first error, which helps debugging, but the program runs more slowly and the interpreter is needed every time it runs.
- An assembler translates assembly language into machine code.
The IDE
- An integrated development environment (IDE) is software for writing programs. It usually has an editor (with syntax highlighting and automatic indentation), error diagnostics, a translator and a run-time environment.
- Debugging tools include breakpoints (pausing the program at a chosen line), stepping through the code line by line, and watching the values of variables.
Key terms
- High-level language
- A programming language with English-like keywords, such as Python.
- Low-level language
- A language close to the hardware: machine code or assembly language.
- Machine code
- Binary instructions that the CPU can run directly.
- Assembly language
- A low-level language that uses short mnemonics, such as ADD.
- Compiler
- A translator that converts a whole program into machine code in one go.
- Interpreter
- A translator that translates and runs a program one line at a time.
- Assembler
- A translator that converts assembly language into machine code.
- IDE
- Integrated development environment: software with tools for writing and testing programs.
- Breakpoint
- A point where a program pauses so the programmer can inspect it.
Quick questions on Programming languages and translators
- Which type of language does the CPU run directly?
- Machine code: Everything else has to be translated into machine code.
- What does a compiler do?
- Translates the whole program into machine code in one go: It produces an executable file.
- What does an interpreter do?
- Translates and runs a program one line at a time: It stops at the first error.
- What does an assembler do?
- Translates assembly language into machine code: Each mnemonic becomes one machine code instruction.
- Which of these is an advantage of a high-level language?
- It is easier to read, write and debug: Its keywords are like English.
- Why might a programmer use assembly language?
- For direct control of the hardware and very efficient code: It suits small embedded systems.
- Why is an interpreter useful while a program is being developed?
- It stops at the first error, which makes debugging easier: You can see exactly where the problem is.
- Which translator produces an executable file?
- A compiler: The executable runs without the compiler.
- What is a breakpoint?
- A point where the program pauses so you can inspect the variables: It is a debugging tool in an IDE.
- What does syntax highlighting do in an IDE?
- Colours the code to make it easier to read and spot errors: Keywords, strings and comments appear in different colours.
- What is assembly language?
- A low-level language using mnemonics such as ADD: It is one step up from machine code.
- Why must high-level code be translated?
- The CPU can only run machine code: A compiler or interpreter does the translation.
Programming languages and translators: exam-style questions and mark schemes
Which translator converts assembly language into machine code? [1 mark]
Answer: Assembler
Compare compilers and interpreters. [4 marks]
- A compiler translates the whole program at once; an interpreter translates one line at a time (1)
- A compiler produces an executable that runs without the translator; an interpreter is needed every time the program runs (1)
- Compiled programs run faster (1)
- An interpreter stops at the first error, which helps debugging; a compiler reports all the errors at the end (1)
Give two reasons why most programs are written in high-level languages. [2 marks]
- They are easier to read, write and debug (1)
- They are portable: the same code can run on different types of processor (1)
Describe three features of an IDE that help a programmer. [3 marks]
- An editor with syntax highlighting or automatic indentation (1)
- Error diagnostics that highlight errors (1)
- Debugging tools, such as breakpoints or stepping through the code, or a run-time environment (1)
Compare compilers and interpreters, and explain when a programmer might use each. [6 marks]
- both translate high-level code into machine code
- a compiler translates the whole program at once, making an executable file
- a compiled program runs quickly, and doesn't need the translator to run
- the source code is hidden, so it can't easily be copied
- a compiler reports errors only after translating the whole program, which makes debugging harder
- an interpreter translates and runs one line at a time
- it stops at the first error, so it's easier to debug while writing the program
- an interpreted program runs more slowly and needs the interpreter every time; use it while developing and a compiler to give the program out
How to answer them: exam technique and command words.
Programming languages and translators: questions and answers
- What is a breakpoint?
- A point where the program pauses so you can inspect the variables. It is a debugging tool in an IDE.
- What does syntax highlighting do in an IDE?
- Colours the code to make it easier to read and spot errors. Keywords, strings and comments appear in different colours.
- What is assembly language?
- A low-level language using mnemonics such as ADD. It is one step up from machine code.
Practise Programming languages and translators: 12 questions