Urgent.News

What's breaking now, across thousands of outlets.

Tech

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

Yantra is a C++ compiler compiler and LALR(1) parser generator that offers a range of core features. The name Yantra, derived from Sanskrit, signifies a machine, specifically a state machine in this context. Building Yantra is straightforward, requiring only the C++ standard library and a CMake build process, resulting in the ycc executable located in the bin/ directory.

To utilize Yantra, one must save a grammar file, such as hello.y, which generates hello.cpp and hello.log files. Compiling these files using any C++23 compiler produces a self-contained parser with its own main() function. The grammar example provided recognizes one or more whitespace-separated alphabetic words, with the -s option allowing direct input feeding to the parser, as opposed to -f for file input or -i for interactive console input.

Unlike most parser generators, Yantra parses the entire input into an Abstract Syntax Tree (AST) first, then walks it top-down, calling semantic actions. This unique ordering enables the parent rule's action to execute before its children are visited. For instance, in the calc.y grammar file, the expression "1 + 2 + 3" is parsed left-associatively as (1 + 2) + 3, with the outer Adding node (root of the tree) printing first, followed by its left child (Number: 1) and right child (another Adding node with its own two children).

This parsing process inherently builds an efficient AST without requiring extra AST classes or a separate walking pass, which would be necessary in hand-written recursive-descent or bottom-up parsers. For a comprehensive understanding of Yantra, it is recommended to refer to the Build Instructions and Tutorial, along with the known limitations.

Additional resources include a GitHub repository (https://github.com/TantrixAuto/lingo) containing a standalone sample project that utilizes Yantra, a language server extension (https://github.com/rajware/yantra-language-server) for syntax highlighting in various IDEs, and the Yantra C++ parser generator itself, which provides lexer, parser, and AST generation in a single tool.

Written by urgent.news from Hacker News's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at github.com →

More in Tech

Realtime Checks and Presence Accuracy for Auction Notification Streams

Short answer: use a realtime API surface that matches authorization checks, but make the data contract own expiry, reconnect, duplicate delivery, and recovery for auction bidder notifications.

  • Separate realtime authorization checks from auction bidder notifications
  • Maintain records with principal ID, auction ID, allowed lots, expiration time
  • Test failure scenarios like token expiration and cursor out-of-order arrival

More from Thursday 1 October →