Lex - A Lexical Analyzer Generator.
A LEX program has three sections: Definitions/Declarations Rules (Pattern → Action) User Code/Auxiliary Functions. Sections are separated by %%.
.l file → lex → lex.yy.c → gcc → Executable
yylex() scans the input and recognizes tokens.
Always choose the longest matching lexeme.
If two patterns match the same longest lexeme, choose the pattern that appears first in the LEX program.
Tokenizes source code into keywords, identifiers, numbers, operators, and symbols.
Can also count words, lines, and characters using pattern-action rules.