Loading...
Follow a short expression from characters to executable behaviour. Compiler stages transform representations; linking and loading solve further problems needed before the program can run.
What you'll be able to do
Lexical analysis groups source characters into tokens such as identifiers, keywords, literals and operators. For total = price + 3, tokens include an identifier, assignment operator, another identifier, addition operator and integer literal. Comments and insignificant whitespace can be discarded, while whitespace that carries meaning in a particular language must be handled according to that language’s rules.
Syntax analysis checks how the tokens fit the grammar, producing a structural representation such as an abstract syntax tree. In total = price +, an operand is missing after the addition operator. Reporting this grammatical error does not establish whether a different, syntactically valid expression calculates the intended total. Identifier and type checks may involve related semantic analysis.
Code generation translates an analysed program representation into target operations, which may be machine code, assembly or an intermediate form. The implementation must preserve the program’s defined meaning. An expression tree helps distinguish price + 3 * quantity from (price + 3) * quantity; the grouping changes the result.
Optimisation seeks improvements such as reduced execution time or resource use without changing required observable behaviour. Constant folding can evaluate 4*5 in advance. Removing a repeated calculation is only valid when its inputs and relevant effects make reuse safe. A compiler cannot generally treat all function calls as pure or assume that floating-point reassociation always preserves identical numerical results.
A library packages reusable operations behind an interface. It can reduce development time, but introduces dependency, compatibility and licensing considerations. A linker combines object modules, resolves references to externally defined routines and produces a suitable linked program representation. Some linking occurs before distribution, while shared-library references may be resolved later.
A loader prepares the program to execute, mapping its code and data into the process environment and arranging the required initial state. Do not describe every pipeline as identical: toolchains can combine stages or target a runtime. Compilation success alone cannot prove that a library will be available at runtime or that the algorithm meets the user’s requirements.
| Stage | Illustrative output or responsibility |
|---|---|
| Lexical analysis | IDENT(total), ASSIGN, IDENT(price), PLUS, INT(3) |
| Syntax analysis | Assignment node whose value is an addition expression |
| Code generation | Operations that load, add and store under a target model |
| Optimisation | Equivalent transformations under stated language rules |
| Linking | Resolve references across separately produced modules |
| Loading | Prepare the executable process environment |
Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.