TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #25833 10
Yantra: an LALR(1) parser generator for C++23

Yantra: an LALR(1) parser generator for C++23 that builds the AST first, then walks it top-down

Yantra is a parser generator: lexer, parser, and AST walker generation, all in one tool, no separate lexer generator needed.

The main thing that's different from Yacc/Bison/Lemon: most LALR tools run your semantic actions during parsing, as each rule reduces, bottom-up, so by the time an action runs you don't know what its parent looks like. Yantra always builds the whole AST first, then walks it top-down in a separate pass, so a parent's action can run before its children are visited. It's still LALR(1) under the hood, bottom-up, table-driven, the top-down walk is layered on top of that, not a trade-off for a different parsing algorithm the way ANTLR's LL(*) gets it for free.

A small example:

expr := expr(a) PLUS expr(b)

%{

std::cout << "Adding" << std::endl;

%}

expr := NUMBER(N)

%{

std::cout << "Number: " << N.text << std::endl;

%}

Running `1 + 2 + 3` through it prints `Adding`, `Number: 1`, `Adding`, `Number: 2`, `Number: 3`, the outer `Adding` fires first, because the whole tree already exists before any action runs.

A single grammar can also define multiple walkers (e.g. one emitting C++, another emitting Java, from the same parse), with the AST and walker classes generated for you either way.

C++23, MIT licensed, no dependencies beyond the standard library. It's young (0.y.z, pre-1.0) and single-maintainer, so there are real gaps, listed honestly in known\_limitations.md rather than glossed over.

GitHub: https://github.com/TantrixAuto/yantra

https://redd.it/1x2kqq0
@r_cpp
GitHub yantra/docs/known_limitations.md at main · TantrixAuto/yantra A C++ parser generator: lexer, parser, and AST generation in one tool. - TantrixAuto/yantra
More from @r_cpp
  1. Oct 11, 2026Right way to test async code https://redd.it/1x2wqgz @r_cpp
  2. Oct 10, 2026Opting in, and back out again https://dryperspective.github.io/posts/opting-in/ https://re…
  3. Oct 10, 2026I’m Building Bursztyn OS a Polish Operating System From Scratch I’m building Bursztyn OS,…
  4. Oct 9, 2026std::variant, operator== and pattern matching I was thinking, wouldn't adding equality com…
  5. Oct 8, 2026Profiles for simplicity and guarantees - Bjarne Stroustrup - CppCon 2026 https://youtu.be/…
  6. Oct 8, 2026How to Fix autoconf-style Configuration Probing https://build2.org/blog/fix-autoconf.xhtml…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →