2.2.15

Compilation Stages

Test yourself

Syntax Analysis, Code Generation & Optimisation

When code is compiled through a compiler, it has to go through 4 stages before it is ready to run.

Illustrative background for Step 2: syntax analysisIllustrative background for Step 2: syntax analysis ?? "content

Step 2: syntax analysis

  • During syntax analysis, the tokenised code from the lexical analysis is compared to the rules of the programming language.
  • If a section or part of the code is found to not fit with these rules, an error is generated with details of what and where it is.
  • It will continue to perform syntax analysis of all of the code and generate more errors if found.
  • A full error report will be given back to the user of all errors found.
  • This differs to interpreted languages as they return one error at a time.
Illustrative background for Step 3: code generationIllustrative background for Step 3: code generation ?? "content

Step 3: code generation

  • Once the code has successfully passed the first two stages, it’s time to generate the code.
  • During this stage object or machine code is generated.
  • This is what the CPU actually works with to make your program run.
Illustrative background for Step 4: optimisationIllustrative background for Step 4: optimisation ?? "content

Step 4: optimisation

  • After your code has been generated into machine or object code it will be optimised for efficiency.
  • The purpose is to make the binary footprint as small as possible and will remove procedures and variables that are written into the code but never used.

Jump to other topics

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Ahead

6.3Thinking Procedurally

6.4Thinking Logically

6.5Thinking Concurrently

7Problem Solving & Programming

8Algorithms

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium