OCR A-Level Computer Science H446
Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation
Software Development
Types of Programming Language
Exchanging Data
Networks
Web Technologies
Data Types and Number Representation
Data Structures
Boolean Algebra
Legal, Moral, Cultural and Ethical Issues
Elements of Computational Thinking
Problem Solving and Programming
Algorithms
Applications Generation
The stages of compilation
- 3 things to know
- Component 01
Overview
Recall questions on lexical analysis, tokens and the symbol table, syntax analysis and the abstract syntax tree, syntax and semantic errors, code generation, optimisation and its cost, and which errors are caught at compile time.
What you need to know
Answer each one before you reveal it.
Put these in the right order and say what each hands to the next: code generation, lexical analysis, optimisation, syntax analysis.
Name the four stages of compilation in order.
Questions from this subtopic
Each one with the model answer underneath.
- 1
Name the four stages of compilation in order.
Model answer
Lexical analysis, then syntax analysis, then code generation, then optimisation.
- 2
What happens during lexical analysis?
Model answer
The source code is read character by character and all unnecessary characters - spaces, tabs, line breaks and comments - are removed. The remaining text is broken into its smallest meaningful units and each is replaced by a token, a short standard code identifying what kind of thing it is. Identifiers and constants that the programmer has invented are entered into a symbol table along with their names and any known information about them.
- 3
What does lexical analysis produce?
Model answer
A stream of tokens, together with a symbol table holding the names of the identifiers and constants used in the program and information about them such as type and scope.
- 4
What is a token?
Model answer
A short standard code standing for one lexical unit of the program - a keyword, an operator, a bracket, an identifier or a literal value. Replacing every unit with a fixed-length token means the later stages work on a compact uniform stream rather than on raw text of varying length.
- 5
What is a symbol table and why is it built during lexical analysis?
Model answer
A table listing every identifier the programmer has used - variable names, constant names, subroutine names - with information gathered about each, such as its data type, its scope and eventually the memory address allocated to it. It is started at lexical analysis because that is the stage that first meets each name, and it is added to and consulted by every later stage, so that for instance syntax analysis can check a variable's type and code generation can find its address.
- 6
Why are comments and whitespace removed at the lexical stage?
Model answer
They carry no meaning for the machine - they exist for human readers. Removing them early makes the token stream smaller and simpler, so every later stage has less to process and does not have to keep stepping over material it must ignore.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Applications Generation, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.