Getting started guide for Boost.Spirit? [closed]
Asked Answered
B

5

34

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?

Battleplane answered 14/7, 2009 at 8:52 Comment(2)
If you want to learn about the new Boost Spirit X3, I would recommend this video. The powerpoint slides are found here.Gaylenegayler
As an engineering challenge, I've implemented BASIC interpreter using Boost.Spirit X3. It's functional enough to run some text-based games from 80-s and other programs. github.com/black-square/BASIC-boost.spirit Please take a look if you have a moment. I would be happy to answer any questions or to hear any feedback. Also, it's MIT licensed so feel free to use it in any way you want.Domicile
H
14

An introductory article from CP

A JSON parser implemented using Boost.Spirit from CodeProject

Spirit Application Repository

Humism answered 14/7, 2009 at 9:27 Comment(3)
Here's my own take at JSON using Spirit V2 github.com/sehe/spirit-v2-json for comparisonTupi
Here's a nice write-up on Dr. Dobbs: http://www.drdobbs.com/cpp/the-spirit-parser-library-inline-parsing/184401692Overleap
I suggest the original boost::spirit docs/tutorials: boost.org/doc/libs/1_40_0/libs/spirit/doc/html/spirit/…Pteranodon
A
8

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.

Artery answered 30/11, 2011 at 13:31 Comment(0)
S
5

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

Sagacious answered 26/10, 2009 at 20:2 Comment(1)
Documentation for Spirit2: boost.org/doc/libs/1_40_0/libs/spirit/doc/html/index.htmlCarangid
O
3

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

Ockeghem answered 12/2, 2015 at 10:9 Comment(0)
D
2

Using Spirit 2.3: Qi and Karma

I think this pdf is quite good for beginners.

Dint answered 20/5, 2016 at 6:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.