Source Code
    ↓
Lexer:  token 
    ↓
Parser
    ↓
AST
    ↓
Semantic Analysis
    ↓
Intermediate Representation (IR)
    ↓
Optimization
    ↓
Code Generation
    ↓
Assembly/Object Files
    ↓
Linker
    ↓
Executable (Machine Code)

1. Lexer (Lexical Analysis)

The lexer breaks raw text into tokens.

Source code

int x = 10 + 20;
String name = "Apex";
int y = "APEX";

Tokens

INT
IDENTIFIER(x)
ASSIGN(=)
NUMBER(10)
PLUS(+)
NUMBER(20)
SEMICOLON(;)

The lexer does not understand program structure.

It only says:

"I found a keyword, identifier, number, operator..."

Rust Example

let age = 23;

Tokens:

LET
IDENTIFIER(age)
EQUALS
NUMBER(23)
SEMICOLON

2. Parser (Syntax Analysis)

The parser takes tokens and checks whether they follow the language grammar.

Tokens