Pratt parsing is presented not merely as a compact expression-parsing algorithm, but as a different way to think about grammar. Instead of attaching semantic actions to production rules, it assigns them to tokens: a “nud” handles a token with nothing to its left, while a “led” handles one that follows an existing expression. Binding-power values determine how expressions group. The parser repeatedly consumes tokens and dispatches through these tables, making the core mechanism small while keeping token-specific behavior in separate functions. The central question is what a token expects on its left.
The author argues that this organization avoids left recursion, backtracking, and the need to undo failed semantic actions; each action runs once and can safely use context or look ahead. It also makes some grammar conflicts visible as collisions in dispatch tables, while warning that combining parsers can still create ambiguities. Empty table entries can serve as extension points for dynamically added syntax, including macros or user-defined operators. The practical mindset shift is illustrated with function calls and indexing: an opening parenthesis or bracket is treated as a led because it follows an expression, and its handler parses the arguments or indexes. The broader claim is that Pratt parsing makes syntax easier to extend and reason about by organizing parsing around the role of each token rather than around whole grammar productions.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.