python-offside-rule-context-sensitive
IN premise — entries/2026/06/21/wiki-Tokenization_lexical_analysis.md
Created 2026-06-21T09:50:11+00:00
Python's off-side rule requires the lexer to maintain a stack of indent levels and emit INDENT/DEDENT tokens, making the lexical grammar context-sensitive.
Summary
Python's indentation rules mean you cannot break source code into tokens in isolation — the lexer must remember the nesting depth it saw in earlier lines before it can decide what tokens the current line produces. This forces every tool that touches Python syntax, from editors to linters to transpilers, to treat tokenization as a stateful, context-dependent process rather than a simple one-pass scan.