How is source code turned into something the processor can run, and what does each stage of compilation do?
The need for, and the characteristics of, translators (assemblers, compilers, interpreters), the stages of compilation (lexical analysis, syntax analysis, code generation, optimisation), and the role of linkers, loaders and libraries.
An OCR H446 answer on translators and compilation: the characteristics of assemblers, compilers and interpreters, when each is used, the four stages of compilation (lexical analysis, syntax analysis, code generation and optimisation), and the roles of linkers, loaders and libraries.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
OCR wants the three types of translator with their characteristics and when each is used, the four stages of compilation in order, and the roles of linkers, loaders and libraries. Expect a "compare a compiler and an interpreter" question and a "describe the stages of compilation" question.
The answer
Why translators are needed
Assemblers, compilers and interpreters
The four stages of compilation
Linkers, loaders and libraries
Examples in context
Python normally uses an interpreter, which is why it is popular for rapid development and scripting; C and C++ are compiled for speed and to ship closed-source binaries. Java compiles to platform-independent bytecode that a virtual machine then interprets or just-in-time compiles, blending the approaches. Dynamic libraries (DLLs on Windows, shared objects on Linux) let many programs share one copy of common code, saving memory. OCR ties this to assembly language and to the trade-offs between high-level and low-level programming.
Try this
Q1. State one advantage of using a compiler rather than an interpreter to distribute software. [1 mark]
- Cue. The executable can be distributed without the source code (protecting it) and runs fast with no translation overhead.
Q2. State what is produced by the lexical analysis stage of compilation. [1 mark]
- Cue. Tokens (with the symbol table begun), after removing whitespace and comments.
Q3. Explain the role of a linker. [2 marks]
- Cue. It combines the compiled object code of separate modules with the library code they use into one executable, resolving references between them.
Exam-style practice questions
Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
OCR 20186 marksCompare the use of a compiler and an interpreter for translating a high-level language program, referring to error reporting, execution speed and distribution of the program.Show worked answer →
Award up to two marks each for error reporting, speed and distribution.
Error reporting: a compiler translates the whole program at once and reports all syntax errors together after the attempt, so debugging happens in batches; an interpreter translates and executes one statement at a time and stops at the first error, which is convenient for development and locating errors.
Execution speed: compiled code runs as native machine code, so it executes quickly with no translation overhead at run time; interpreted code is translated each time it runs, so it is slower, and a statement inside a loop is retranslated on every pass.
Distribution: a compiler produces a standalone executable that can be distributed without the source code (protecting it) but is platform-specific; an interpreter needs the source code and the interpreter present on the target machine, which aids portability but exposes the source. Markers reward a clear point on each of the three aspects.
OCR 20225 marksDescribe the stages of compilation, naming what happens at lexical analysis, syntax analysis and code generation.Show worked answer →
Award marks for each stage described in order (up to 5).
Lexical analysis: the source code is read and broken into tokens; whitespace and comments are removed and a symbol table is begun to record identifiers and keywords.
Syntax analysis (parsing): the tokens are checked against the rules of the language grammar, building a structure such as an abstract syntax tree; syntax errors are reported here and the symbol table is completed.
Code generation: the syntax tree is translated into object code (machine code or an intermediate form). An optional fourth stage, optimisation, then improves the code to run faster or use less memory, for example removing redundant instructions. Markers reward tokens at lexical, grammar checking at syntax, and machine/object code at code generation.
Related dot points
- Types of operating system (distributed, embedded, multitasking, multiuser, real-time) and software development methodologies (waterfall, agile, extreme programming, spiral, rapid application development), with their merits and appropriate uses.
An OCR H446 answer on the types of operating system (distributed, embedded, multitasking, multiuser, real-time) and the software development methodologies (waterfall, agile, extreme programming, spiral, rapid application development), with their merits, drawbacks and appropriate uses.
- Programming paradigms (procedural, low-level / assembly and object-oriented), the need for and characteristics of different levels of programming language, and the core principles of object-oriented programming: classes, objects, methods, attributes, encapsulation, inheritance and polymorphism.
An OCR H446 answer on programming paradigms and language levels: procedural, low-level and object-oriented programming, the characteristics of high-level versus low-level languages, and the OOP principles of classes, objects, methods, attributes, encapsulation, inheritance and polymorphism.
- The nature of applications generation, the role of utilities and the difference between systems and application software, and the types and uses of software including open source versus closed source and custom-written versus off-the-shelf.
An OCR H446 answer on applications generation and the types and uses of software: the role of utilities, the difference between systems and application software, and the trade-offs of open source versus closed source and custom-written versus off-the-shelf software.
- Assembly language and the relationship between assembly instructions and machine code, the instruction set with opcode and operand, the Little Man Computer model, and the addressing modes (immediate, direct, indirect and indexed).
An OCR H446 answer on assembly language and addressing modes: how assembly maps to machine code, the opcode-and-operand structure of an instruction, the Little Man Computer model, and the immediate, direct, indirect and indexed addressing modes with examples.
- The functions of an operating system: memory management (paging, segmentation, virtual memory), interrupts and the interrupt service routine, scheduling algorithms, and the distinction between systems software (operating systems, utilities) and application software.
An OCR H446 answer on the functions of an operating system: memory management with paging, segmentation and virtual memory, interrupts and the interrupt service routine, scheduling algorithms, and the difference between systems software (operating systems and utilities) and application software.