Question

I've been looking recently at Boost.Spirit (the version included in Boost 1.39), however I'm quite confused from the docs alone. What I'm looking for is for an example of a toy language implemented with Boost.Spirit -- something along the lines of a tiny Javascript or Lua or so, where you basically create an AST and process is. I'd be happy if it just supports function/variable definitions and the basic operators, I just want to see how you would create a normal AST using Boost.Spirit, and how to implement basic rules like identifiers, declarations, etc.

So far, I've tried the calculator example, but it's unclear for me how to implement a larger grammar with Spirit. The mini_c example which is bundled on the other hand looks quite complicated already, and it's not too well documented. Is there some easy to understand guide to Boost.Spirit out there, or a book maybe?

OTHER TIPS

The Spirit documentation includes examples and tutorials. An example for generating an AST for a mini XML-like language is included. A very useful overview presentation by Joel de Guzman and Hartmut Kaiser is also available.

please keep in mind there is a newer boost spirit version with the completely new approach towards generating AST.

The book The Boost C++ Libraries has a chapter about Spirit which I personally found pretty useful. It's available online, here's a direct link:

Chapter 11. Boost.Spirit

Using Spirit 2.3: Qi and Karma

I think this pdf is quite good for beginners.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top