frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

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

https://github.com/TantrixAuto/yantra
10•renjipanicker•2h ago
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://github.com/TantrixAuto/yantra/blob/main/docs/known_l...

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

Feedback and questions are all welcome. I'll be around.

Comments

kazinator•53m ago
Yacc has mid-rule actions which can be used to propagate information from left siblings to right siblings, as well as to children (embedded nonterminal symbols).

Of course, it's not the same as having the parse tree all done from a previous pass and just walking it to do semantics.

userbinator•34m ago
It's a little surprising to see new parser generators being written, long after the vast majority of compilers have already settled on recursive descent / precedence climbing (including https://news.ycombinator.com/item?id=49913192 , which is currently nearby on the front page.)
fithisux•12m ago
Congratulations. We need more of these tools. I'll give it a try.

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

https://github.com/TantrixAuto/yantra
12•renjipanicker•2h ago•3 comments

Show HN: Lathoa, a math app for kids where the AI is wrong on purpose

https://lathoa.ai/en
42•thanouil1411•14h ago•20 comments

Show HN: Ledge.sh – Runnable Markdown Notes

https://ledge.sh
82•dancablam•1d ago•40 comments

Show HN: JBR-001 – An open-source 3D printable desktop robot

https://projecthub.arduino.cc/syntheticaidata/jbr-001-a-desktop-companion-robot-powered-by-arduin...
124•gvuksic•1d ago•29 comments

Show HN: A working 3D model of an Enigma machine

https://enigma.design
95•primitivesuave•1d ago•40 comments

Show HN: Dental Scope – Interactive 3D dental anatomy

https://dental-scope.com/
118•Zeruxe•2d ago•62 comments

Show HN: Smartly – Plain English to shell commands, with GNU/BSD awareness

https://smartlycli.com/
2•rizwanreza•2h ago•0 comments

Show HN: Perspica – A semantic diff for reviewing code

https://github.com/sshah03/perspica
9•sshah03•8h ago•3 comments

Show HN: Kanmaps – Product roadmaps like videogame skill trees

https://kanmaps.com/show
6•pasharayan•3h ago•3 comments

Show HN: Using 2D DFT, dithering, etc. to maximize eInk manga image quality

https://github.com/ciromattia/kcc
77•seam_carver•2d ago•20 comments

Show HN: Parrot – Open-Source Smart Meeting Recorder with Co-Pilot on Mac

https://openparrot.app
31•turantekin•13h ago•12 comments

Show HN: Strata – an expressive semantic layer that can say no to your LLM

https://strata.do/
18•ajoski9•13h ago•8 comments

Show HN: NSL – WSL for Linux

https://frostyard.github.io/nsl/
161•bketelsen•1d ago•101 comments

Show HN: DragomanD – local language translator for Linux

https://dragomand.l10n-bg.dev/
6•eniac111•7h ago•0 comments

Show HN: Real-time Solar System with 526k asteroids and all tracked satellites

https://space.bl2.net/
379•wanick•1d ago•106 comments

Show HN: Real-time raytracing around a black hole

https://rivendell.dmitrybrant.com/blackhole/
2•dmitrybrant•7h ago•0 comments

Show HN: CLI and TUI control for dps150 power supply

https://github.com/hmldns/dps150ctl
2•Homo__Ludens•8h ago•0 comments

Show HN: TurboGPT: train 22KiB transformer in 13s

https://github.com/lostmsu/TurboGPT
54•lostmsu•1d ago•10 comments

Show HN: HN.watch – Videos of all Hacker News posts

https://hn.watch/
215•mrborgen•2d ago•97 comments

Show HN: Domainpuff.com – Find memorable domain names within your budget

https://domainpuff.com/
2•brunoelylemon•8h ago•1 comments

Show HN: Destroy Any Website with Stickman

https://destroy.spritefusion.com/
184•HugoDz•2d ago•40 comments

Show HN: Jevstiller – Distill Jev into a local model, with a disagreement bound

https://jevstiller.pages.dev/posts/the-guarantee/
65•tgluck•1d ago•15 comments

Show HN: Free alternative to graphics design giants

https://scissor.studio/
139•sia_xi•2d ago•50 comments

Show HN: PaperMono, e-ink fridge magnet shopping list with mobile web page

https://github.com/seamusc/papermono-shopping-list
149•seamus_c•2d ago•62 comments

Show HN: Kyno – Direction as a first-class primitive for AI agents

https://cizambra.github.io/kyno/
4•cizambra•11h ago•0 comments

Show HN: I built a free Burp/Caido alternative but, zero setup - API Testing

https://apiaxess.dev
30•coding-maniac•11h ago•5 comments

Show HN: Token compression CLI to save Codex/Astra costs

8•yolandac•11h ago•4 comments

Show HN: Datastory, Data storytelling with AI and an open knowledge graph

https://www.datastory.tech
6•DanielLapidus•11h ago•0 comments

Show HN: WattzGOAT – an intentionally vulnerable web app for security training

https://github.com/wattzgoat/wattzgoat-web
3•wattzgoat•12h ago•0 comments

Show HN: Jev Plays Pokémon Red

https://jev-pokemon.vercel.app/
281•pancomplex•5d ago•124 comments