Describe the four stages of compilation.

The first stage is lexical analysis which takes the source code as an input and: • Removes whitespace and comments; • Converts remaining code into tokens, by breaking down the code by recognising reserved words, operators and variables; • Creates a symbol table which includes information on variables such as scope and data type. The second stage is syntax analysis which checks the code to ensure it obeys the rules of syntax. An abstract syntax tree (AST) is created and if a part of the code does not fit into the AST then a syntax error has occurred and the compiler generates a syntax error report to send to the user. The third stage is code generation where the code is translated into object code or machine code. The final stage is code optimisation where the compiler attempts to optimise both space and time efficiency. This is achieved by: • Removing unused variables and subroutines; • Searching for more efficient alternatives to sets of instructions.                                                                                              

Related Computer Science A Level answers

All answers ▸

Explain the key differences between Von Neumann and Harvard CPU architectures.


What is a binary tree? What is the time efficiency when searching a balanced binary tree of size n nodes and why? What is the advantage of using a binary tree rather than an ordinary list?


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences