There are a number of steps to the C compilation process.
- Write code. Obviously.
- Preprocess. A preprocessor removes comments, expands macros, and includes header files.
- Lex. A lexer converts the source code into a sequence of tokens.
- Parse. A parser converts the sequence of tokens into an abstract syntax tree (AST).
- Type check. A type checker annotates the AST with the type of every expression and variable.
- Generate code. A code generator converts the AST into assembly code.
- Turn the AST into assembly-like code with infinite registers.
- Add a variety of optimizations.
- Allocate registers and memory locations.
- Assemble the results.
- Link. A linker connects the assembly code with the libraries and system calls it needs to function.
- Load. A loader loads the executable into memory.