hn.today

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

github.com24 points15 comments
Screenshot of Show HN: Yantra – an LALR(1) parser generator for C++

Yantra is an LALR(1) parser generator and "compiler compiler" implemented in C++ that produces lexers, parsers, and ASTs with no dependencies beyond the C++ standard library. Core features include an integrated Unicode/UTF‑8-aware lexer with multi-mode support, a lexer-driven push parser that feeds tokens as characters arrive, automatic AST construction, and top‑down AST walkers that run semantic actions after the tree is built. Code generation can be emitted as a single amalgamated .cpp with main() for quick prototypes or as separate .hpp/.cpp files to drop into existing C++ projects. Building is done with CMake and the distributed ycc executable generates parsers from simple grammar files; examples show full workflows from grammar to compiled C++23 binary.

Yantra’s distinguishing design is that it uses LALR(1) parsing but always constructs a complete parse tree first and then walks it top‑down, allowing parent rule actions to execute before their children - unlike traditional Bison/Yacc/Lemon workflows where actions run during reductions. Compared with ANTLR, Yantra achieves top‑down walking while remaining LALR(1), targeting C++ only and avoiding any Java/JVM dependency; compared with Tree‑sitter, it is not aimed at incremental editor parsing. The project is MIT‑licensed, authored by Renji Panicker, smaller and newer than mature alternatives, and documents known limitations and example clients (sample project and a community language‑server extension).

Read on github.com15 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.