levo

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.

Your recallNot started
Key term

What happens during syntax analysis?

Key term

Put these in the right order and say what each hands to the next: code generation, lexical analysis, optimisation, syntax analysis.

Process

Name the four stages of compilation in order.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Name the four stages of compilation in order.

    Model answer

    Lexical analysis, then syntax analysis, then code generation, then optimisation.

  2. 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. 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. 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. 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. 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.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

A0 + 0 gives 0.
B0 + 1 gives 1.
C1 + 1 gives 0 carry 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

A global variable means a variable reachable from anywhere in the program.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

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.