levo

Applications Generation

The stages of compilation

  • 3 things to know
  • Component 01
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

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

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.