← Thu, Oct 1 digest

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

read article ↗ hn thread ↗

Yantra is a new C++23 LALR(1) parser generator that builds a full AST first and executes top-down walker passes, avoiding bottom-up reduction limitations.

summary is enough The README provides a concise technical overview and comparisons to Bison and ANTLR, but deep evaluation requires testing the codebase.

summary

Yantra is a new C++23 LALR(1) parser generator featuring an integrated multi-mode lexer, UTF-8 support, and a built-in AST builder. Unlike traditional LALR tools that execute semantic actions bottom-up during reduction, Yantra builds the complete AST first and runs top-down walkers in a separate pass. This design allows parent rules to execute actions before visiting children without manual AST boilerplate. It has zero external dependencies beyond the C++ standard library and supports generating an amalgamated single-file parser.

key points

  1. Yantra builds a complete AST first and executes a top-down walker pass, separating parsing from semantic evaluation unlike traditional bottom-up LALR tools.
  2. The tool requires zero external dependencies outside the C++23 standard library and can output an amalgamated single-file parser with a built-in main function.
  3. It includes an integrated multi-mode push-based lexer with native UTF-8 support, removing the need for a separate tool like Flex.

who should read it

C++ developers and compiler engineers looking for a lightweight alternative to traditional parser generators.

discussion positive

consensus

Commenters welcome the new tool while discussing the historical shift away from parser generators toward recursive descent, particularly due to error-handling challenges.

pushback

A commenter pointed out a potential associativity error in the documentation's example grammar.

best comment by renjipanicker ↗

Mostly still true, yeah. A few tools have made real progress on error tolerance, continuing past a mistake rather than just stopping, tree-sitter is probably the best example, it's explicitly built to produce a best-effort tree from broken input, which is why it's good for editors. ANTLR also has configurable recovery strategies, single-token insertion/deletion heuristics and the like.

But "tolerant" isn't the same as "as good as hand-written." A hand-rolled recursive descent parser can say something like "missing semicolon after return statement" because the code knows exactly what …

The author transparently details current limitations regarding syntax error recovery compared to hand-written parsers.

Generated by an LLM from the article and thread. Check the sources before relying on it.