Source Code
↓
Lexer: token
↓
Parser
↓
AST
↓
Semantic Analysis
↓
Intermediate Representation (IR)
↓
Optimization
↓
Code Generation
↓
Assembly/Object Files
↓
Linker
↓
Executable (Machine Code)
The lexer breaks raw text into tokens.
int x = 10 + 20;
String name = "Apex";
int y = "APEX";
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..."
let age = 23;
Tokens:
LET
IDENTIFIER(age)
EQUALS
NUMBER(23)
SEMICOLON
The parser takes tokens and checks whether they follow the language grammar.