lexer
A lexer, or lexical analyzer, is a software component that performs lexical analysis by reading a stream of characters from a program's source code and grouping them into tokens. Each token represents a basic syntactic unit, such as a keyword, an identifier, a numeric or string literal, or an operator, along with optional metadata like its type, value, and position.
The lexer scans the input left to right, applying a set of patterns (typically expressed as regular
Common token categories include keywords (if, while), identifiers (variable names), literals (numbers, strings), operators (+, -, *), punctuation (commas,
The token stream produced by the lexer is consumed by the parser or interpreter, which uses the