Now we shall look in detail on how compilers produce object code. You are not expected to know how interpreters work internally nor will you be expected to know any of the mathematical constructs surrounding compiling. Compiling is a complicated process and requires a large amount of processing. To make this simpler the compiling task is separated into a number of phases. Each phase produces something for the next phase to work on. You are expected to give an overview of some of the main phases and also how they roughly work.

The compiler is a very complicated program. It must perform many different tasks in order to compile the code. Some of these tasks include -

  • Parsing the source code (Lexical analysis)
  • Syntax analysis
  • Type checks
  • Machine code generation
  • Code block sequencing
  • Register allocation
  • Optimizations
  • Linking of libraries

Some of these operations have been simplified for the A-Level course but just looking at this list shows why compilers are complicated. Each time the compiler performs a task it must go over all of the source code. This is known as a pass or phase. Each phase takes the compiler one step closer to the final object code. At the end of each phase the compiler will have a result most of which is never seen by the programmer.