A flex program consists of three sections:
1. A definition section containing declarations and options.
2. A rules section listing patterns and actions.
3. A subroutines section containing C code copied to the generated scanner.
The scanner reads from standard input by default and returns tokens consisting of the token type and value. Flex matches the longest pattern first or the first pattern if lengths are equal.