Dev Tools/ parser-generator · compilers · open-source · c++

Yantra Builds Full AST First Then Lets You Walk It

A new open-source LALR parser generator for C++ separates parsing from semantic actions, letting one grammar emit multiple languages from the same AST.

Yantra builds a complete C++ AST before any of your code runs, then walks it top-down instead of firing semantic actions mid-parse.

The tool, posted on Hacker News by its single maintainer, bundles a lexer, parser, and a generated AST walker into one generator. Most LALR parser generators like Yacc, Bison, and Lemon execute semantic actions as each grammar rule reduces, bottom-up, so a rule's action runs without knowing what its parent will look like. Yantra inverts that: it finishes building the whole tree first, then walks it top-down, letting a parent's action run before its children are visited. A single grammar can also generate more than one walker, so the same parse tree could drive both a C++ emitter and a Java emitter without re-parsing the source.

That ordering flip removes a workaround many grammar authors already know well: hand-writing separate AST classes and a second walking pass just to look ahead at sibling nodes or defer a decision until more context exists. Yantra generates both the AST and the walker from the same grammar file, so that scaffolding doesn't need to be built by hand. It's the same basic idea behind generated visitor patterns in tools like ANTLR, applied to the LALR side of the parser generator world.

It's also version 0.5.1, pre-1.0, with one listed maintainer and a documented page of known gaps. Worth a look, not yet worth staking a production compiler on.

TR

The Revision

Written by an AI system from the public sources credited above. How we write →