How is source code translated to run, and what does a compiler actually do?
Understand assemblers, compilers and interpreters, the differences between them, the stages of compilation (lexical analysis, syntax analysis, code generation and optimisation), and intermediate code.
A focused answer to AQA A-Level Computer Science 4.6.5, covering assemblers, compilers and interpreters and their differences, the stages of compilation (lexical analysis, syntax analysis, code generation and optimisation), and intermediate code such as bytecode.
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
AQA wants you to distinguish assemblers, compilers and interpreters, give the advantages of each, describe the stages of compilation (lexical analysis, syntax analysis, code generation and optimisation), and explain intermediate code.
Assemblers, compilers and interpreters
The reason interpreted code is slower is subtle and worth stating: a statement inside a loop is re-translated on every single iteration, whereas a compiler translates it once and the processor reruns the resulting machine code directly. The trade-off is therefore between development convenience (the interpreter's immediate feedback and portability) and run-time performance (the compiler's fast, standalone output). The compiled executable is also tied to one processor architecture, because it is native machine code, which is why a program compiled for one platform will not run on another.
The stages of compilation
These stages connect to the theory of computation: lexical analysis recognises tokens that can be described by regular expressions (and so by finite state machines), while syntax analysis checks structure against a context-free grammar, which needs the greater power of a pushdown parser to handle nesting such as matched brackets. This is exactly why the two analysis stages are separate, each matched to the kind of language it must recognise. Code generation and optimisation then translate the validated structure into efficient machine code.
Intermediate code
The bytecode approach is a deliberate middle ground. Pure compilation gives speed but no portability (the executable is tied to one machine); pure interpretation gives portability but is slow. Compiling once to bytecode and then running it on a virtual machine, sometimes with just-in-time compilation to native code at run time, captures much of the speed of compilation while keeping the portability of interpretation, which is why it underpins widely deployed languages.
Exam-style practice questions
Practice questions written in the style of AQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AQA 20195 marksCompare a compiler and an interpreter. In your answer, state how each translates the source code, the effect on execution speed, how errors are reported, and which is better suited to developing a program.Show worked answer →
A compiler translates the entire high-level program into machine code before it runs, producing a standalone executable; an interpreter translates and executes the program one statement at a time as it runs.
Compiled code runs faster because translation happens once, in advance, and the processor then executes native machine code directly; interpreted code runs slower because each statement is translated every time it is executed, and re-translated on every loop iteration.
A compiler reports all errors together after attempting to compile the whole program; an interpreter reports an error as soon as it reaches the offending statement and then stops.
An interpreter is better suited to development because errors are reported immediately at the point they occur, making debugging easier, and code can be run and tested without a full compile.
Markers reward the whole-program versus statement-by-statement translation, the speed difference with a reason, the error-reporting difference, and choosing the interpreter for development with justification.
AQA 20214 marksDescribe the lexical analysis and syntax analysis stages of compilation, stating what each produces and one type of error it can detect.Show worked answer →
Lexical analysis reads the source code character by character and groups it into tokens (keywords, identifiers, operators, literals), removing white space and comments and beginning a symbol table of identifiers. It can detect errors such as an invalid character or symbol that does not form a valid token.
Syntax analysis (parsing) takes the stream of tokens and checks them against the grammar rules of the language, building a parse tree of valid structures. It can detect syntax errors such as a missing bracket or a statement that does not follow the grammar.
Markers reward stating that lexical analysis produces tokens (and a symbol table) and detects invalid tokens, and that syntax analysis produces a parse tree and detects grammar or syntax errors.
Related dot points
- Understand the classification of programming languages by level (low and high) and by paradigm (imperative, object-oriented, declarative and functional), and the use of machine code and assembly language.
A focused answer to AQA A-Level Computer Science 4.6.4, covering the classification of programming languages by level (low and high) and by paradigm (imperative, object-oriented, declarative and functional), and the use of machine code and assembly language.
- Understand the relationship between hardware and software, the classification of software into system and application software, and the role of the operating system and utility programs.
A focused answer to AQA A-Level Computer Science 4.6.1, covering the relationship between hardware and software, the classification of software into system and application software, and the role of the operating system and utility programs.
- Understand regular expressions and regular languages, the link between regular expressions and finite state machines, the limits of regular languages, and context-free languages described by a BNF grammar.
A focused answer to AQA A-Level Computer Science 4.4.3 and 4.4.4, covering regular expressions and regular languages, their link to finite state machines, the limits of regular languages, and context-free languages described using BNF.
- Understand the stored program concept, the Von Neumann architecture, the Harvard architecture, and the differences between them.
A focused answer to AQA A-Level Computer Science 4.7.2, covering the stored program concept, the Von Neumann architecture, the Harvard architecture, and the differences between them.
- Understand the logic gates NOT, AND, OR, XOR, NAND and NOR, their truth tables, combining gates into logic circuits, and simplifying expressions using Boolean algebra.
A focused answer to AQA A-Level Computer Science 4.6.2 and 4.6.3, covering the logic gates NOT, AND, OR, XOR, NAND and NOR, their truth tables, building logic circuits, and simplifying Boolean expressions using the laws of Boolean algebra.
Sources & how we know this
- AQA A-level Computer Science (7517) specification — AQA (2015)