‹ BackHN Continuity

Thread

Show HN: Yantra – an LALR(1) parser generator for C++

33 points · 17 comments · renjipanicker

  1. userbinator · · focus · HN ↗
    It&#x27;s a little surprising to see new parser generators being written, long after the vast majority of compilers have already settled on recursive descent &#x2F; precedence climbing (including <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49913192">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49913192 , which is currently nearby on the front page.)
    1. renjipanicker · · focus · HN ↗
      Fair and true. Most production compilers (Clang, rustc, Go) have moved to hand-written recursive descent, largely for error messages and debuggability: a hand-rolled parser can say exactly what went wrong and try to recover, a generated one is working from a state table.

      One thing worth separating out though: recursive descent is already top-down, so it gets &quot;build the tree, then decide what to do with it&quot; for free, the same way ANTLR&#x27;s LL(*) does. The intresting part of what I built is that it&#x27;s getting that capability while keeping LALR&#x27;s bottom-up table-driven parsing.

      Where a grammar-first tool like this is more useful is smaller or evolving DSLs, where you want the grammar as a readable, declarative spec with automatic conflict detection instead of hand-tuned lookahead logic, and cases like generating multiple outputs (e.g. C++ and Java) from one grammar, which is awkward to bolt onto a hand-rolled parser after the fact.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.