Signed up recently but had issues with the confirmation email?

Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.

Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.

Revision notesQuestionsFor schools
Revise Computing
Log inStart revising free
Revision notesQuestionsFor schoolsLog in

© 2026 Revise Computing · revisecomputing.co.uk

Worried about something?Question Bank UpdatesPrivacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).

Knowledge/A Level/H446/01 Computer systems/Applications Generation/Stages of compilation

Stages of compilation: lexical analysis, syntax analysis, code generation and optimisation

Stages of compilation (lexical analysis, syntax analysis, code generation and optimisation)

1.2.2 Applications Generation

Practise exam questions

Applications Generation — Note 5 of 6

Candidates need to understand that there are a number of stages involved in compilation. Candidates need to understand how lexical analysis works and how the code is converted into tokens with the removal of unnecessary elements (e.g. comments and whitespace). Candidates need to understand how syntax errors are identified and reported at the end of the syntax analysis. Candidates need to understand how the abstract syntax tree will be fed into the next stage of code generation, and that the object code is then created. Candidates need to understand why optimisation is important and how the results of lexical analysis feeds into syntax analysis, and how the tokens are checked to ensure they meet during (and after) code generation.

What you need to know

A compiler translates source code in several stages. Each stage takes the output of the previous one, gradually turning human-readable code into efficient machine code and reporting errors along the way.

What to know

  • Lexical Analysis: whitespace and comments are removed; the code is split into tokens (keywords, identifiers, operators, constants); identifiers are added to the symbol table.
  • Syntax Analysis: the tokens are checked against the grammar rules of the language. Syntax errors are reported. An abstract syntax tree is built to represent the structure of the program.
  • Code Generation: the abstract syntax tree is converted into object code (machine code) for the target processor.
  • Optimisation: the code is changed to run faster or use less memory without changing what it does, e.g. removing redundant or unreachable code, or replacing a calculation with a simpler equivalent.
  • Optimisation can take place before and during code generation.
  • Over-optimisation can make compilation slower and occasionally introduce errors, so it is a trade-off.

Code examples

Lexical analysis turns a line of code into tokens
text
Source:  total = total + price  // add price

Tokens:  <identifier: total> <operator: => <identifier: total>
         <operator: +> <identifier: price>

Comment and whitespace removed; 'total' and 'price'
are added to the symbol table.

Key terms

Token

The smallest meaningful unit of code, e.g. while, count, <=, 10.

Symbol table

A table of the identifiers (variables, subroutines) in the program with information such as data type, scope and memory address.

Exam technique

  • Tip:Learn the stages in order and say what each stage TAKES IN and PRODUCES: source code → tokens → abstract syntax tree → object code → optimised object code. In a long answer, also justify WHY each stage is needed, and say that a linker then joins any library code to the object code.
  • Tip:If a question gives you code, take your examples from it: name a comment that is removed, an identifier added to the symbol table and a keyword turned into a token. A correct general description with no examples from the code can score nothing.
  • Tip:If asked for the PURPOSE of optimisation, say what it achieves (the program runs faster, or uses less memory or fewer resources), not how the code is changed.
  • Mistake:Saying lexical analysis finds syntax errors. Lexical analysis only finds invalid tokens; grammar errors are found during syntax analysis.
  • Mistake:Thinking a program that passes syntax analysis will run correctly. It only follows the grammar rules: it can still fail when it is linked or run, or give the wrong results.

Past exam questions

  • June 2025Paper 1Q6(b)(i)4marks
  • June 2022Paper 1Q5(c)5marks
  • June 2022Paper 1Q5(d)2marks
  • June 2019Paper 1Q8(f)3marks
  • June 2019Paper 1Q8(g)1mark
  • June 2017Paper 1Q10(d)(ii)9marks

Ready to test yourself?

Practise 1.2.2 questions
← Previous noteTranslators: interpreters, compilers and assemblers1.2.2 Applications GenerationNext note →Linkers and loaders and use of libraries1.2.2 Applications Generation

Back to Applications Generation

Applications Generation

Note 5 of 6

  1. 1The nature of applications, justifying suitable applications for a specific purpose
  2. 2Utilities
  3. 3Open source vs closed source
  4. 4Translators: interpreters, compilers and assemblers
  5. 5Stages of compilation: lexical analysis, syntax analysis, code generation and optimisation
  6. 6Linkers and loaders and use of libraries
Topic overview