Urgent.News

What's breaking now, across thousands of outlets.

Tech

Pratt parsing is a black box

Most Pratt parsing tutorials spend a lot of time explaining Pratt's algorithm without covering the important properties that actually matter. However, it's essential to understand the mindset behind Pratt parsing. Douglas Crockford, in his 2013 GOTO conference talk, highlighted that Pratt reduces parsing, a complicated task, to a simple question: "What do we expect to see to the left of a token?"

Pratt parsing simplifies the process by registering semantic actions to terminals (nuds and leds) instead of production rules, used in traditional parsing techniques. This departure from traditional methods has several advantages. For instance, it eliminates the need to worry about left-recursion problems, which are a challenge in traditional parsing techniques like LL(k). Since the semantic action is triggered by the consumed token, left-recursion is not an issue.

Additionally, the parsing engine doesn't need to backtrack or test alternatives, leading to a faster and more memory-efficient parsing process. Semantic actions in Pratt parsing run exactly once, allowing side-effects without the need to rollback to a previous state. This property enables name reservation/release on lexical scope through a shared context object, used in the author's compiler.

Pratt parsing also allows the semantic action to look arbitrarily far ahead, enabling the use of PEG parsers or layered Pratt parsers within actions. While Pratt eats only one token at a time, the nuds and leds can consume multiple tokens in a single round, unlocking the power of parser combinators. This makes grammar ambiguities become table collisions, reducing the time spent on simpler ambiguity cases.

Combining multiple parsers with Pratt also allows for grammar amalgamation, though grammar designers still need to work on avoiding ambiguities.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at vinipsmaker.github.io →

More in Tech

Which Tech Companies Started Using Trump's Phrase 'Super Intelligence'?

CNBC reports: A month after President Donald Trump ordered that "super intelligence" replace the term artificial intelligence within executive branch departments and agencies, his leading tech allies…

  • Elon Musk renamed SpaceX AI division to SpaceXSI
  • Mark Zuckerberg highlighted Meta's goal of personal superintelligence
  • Amazon's Andy Jassy continued using AI extensively

More from Sunday 1 November →