Fly Labs
Buy me some API creditsAsk FlyBot

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

Yantra is a C++ parser generator: lexer, parser, and AST walker all generated from one tool. It builds the whole AST first, then walks it.Most LALR parser generators (Yacc, Bison, Lemon) run your semantic actions during parsing, as each rule reduces, bottom-up.That means at the time a rule's action runs, you don't yet know what its parent looks like. This pushes a lot of grammars toward hand-built AST classes and a separate walking pass whenever you need to look ahead into siblings or defer a decision until more context is available.On the other hand, Yantra always builds the whole AST first, then walks it top-down in a separate pass, calling your semantic actions as it goes. A parent rule's action can run before its children are visited.A single grammar can define more than one walker. For example, one that emits C++, another that emits Java, from the same parse. The AST and the walker classes are both generated for you.A small example (full version, with compile commands, in the README): start := expr; expr := expr(a) PLUS expr(b) %{ std::cout << "Adding" << std::endl; %} expr := NUMBER(N) %{ std::cout << "Number: " << N.text << std::endl; %} NUMBER := "\d+"; PLUS := "\+"; WS := "\s+"!; Running this on "1 + 2 + 3" prints: Adding Number: 1 Adding Number: 2 Number: 3 The outer "Adding", the root of the tree, prints first, before either of its children. That's only possible because the whole tree exists before any action runs.Some other things about it: integrated lexer with mode support (for things like nested comments), an optional amalgamated single-file output mode with a generated main(), C++23, MIT licensed.It's young (0.5.1, pre-1.0) and single-maintainer, so treat it as early. I'd rather know what breaks than have it look more finished than it is.Known gaps are listed at https:/&#x2

Hacker NewsToolAISource
0Sign in to voteCopy link

FL score

65

out of 100

Verdict

VALIDATE

medium confidence

Competition

No competitor data yet

Trend

No signal yet

Yantra is a C++ LALR(1) parser generator that builds a full AST before walking it, enabling more flexible semantic actions.

The pain

Existing LALR(1) parser generators force semantic actions during parsing, limiting context awareness and pushing developers to write separate AST walkers.

The gap

No widely used LALR(1) parser generator for C++ currently builds the entire AST first and supports multiple walkers from one grammar, creating a niche opportunity.

Build angle

A single skilled developer can build and maintain the tool, but growth and support may require more resources and community involvement.

Strengths

  • Addresses a specific technical limitation in parser generators
  • Integrated lexer with mode support and modern C++23 features
  • Generates both AST and walker classes, simplifying multi-target code generation
  • Open source with permissive MIT license

Risks

  • Niche market with limited paying customers
  • Competition from established tools like Bison and Lemon
  • Single maintainer risk and early-stage maturity
  • Unclear monetization and adoption strategy

Questions about this idea?

FlyBot reads the scoring and gives you a second opinion on “Yantra – an LALR(1) parser generator for C++”.

Open FlyBot