Welcome to Spirit

Spirit is a set of C++ libraries for parsing and output generation implemented as Domain Specific Embedded Languages (DSEL) using Expression templates and Template Meta-Programming. The Spirit libraries enable a target grammar to be written exclusively in C++. Inline grammar specifications can mix freely with other C++ code and, thanks to the generative power of C++ templates, are immediately executable.

Spirit is part of Boost Libraries, a peer-reviewed, open collaborative development effort.

Jul ’11 12

Spirit V2.5 is now available as part of the recently released Boost V1.47. I suggest you look at the What’s New documentation page for a list of things changed. This is a very important release for Spirit, mostly in the area of feature consolidation and less so by adding new functionality. It brings a lot of unification and quite some speedup in the area of attribute handling, both for parsers (Qi) and generators (Karma). Most of the newly added features are in the area of unification of the overall user experience as well. The things added to the Lexer should finally resolve some long standing requests. Most importantly, we are very excited about having added full compatibility with the newly released Phoenix V3 library.

Generally, all changes are supposed to be fully backwards compatible. If you run into problems with your existing code, please tell us by leaving a comment or by sending a message to the Spirit mailing list (as described on our Support page).

Tagged with:
Feb ’11 26

Frank Dellaert was asking a valid question on the Spirit mailing list where he pointed out some things he was not able to understand. His question clearly uncovered an inconsistency in Spirit’s API. This lead us to implement some minor additional feature, which in the end turned out to make more uniform the way semantic actions are handled.

Continue reading »

Tagged with:
Feb ’11 12

Narinder Claire asked a seemingly innocent question on the Spirit mailing list the other day. After starting to write an answer I realized that this question is not innocent at all as it touches the very fabric of Spirit: the rules of attribute handling. Many people have a hard time to properly understand what is going on in the nether regions of Spirit. More importantly, they have a hard time to understand why is Spirit implemented the way it is.

The new article Attribute Propagation and Attribute Compatibility not only answers Narinders questions but tries to explain those important concepts in more detail.

Tagged with:
Dec ’10 03

These are links to the slides and video of Michael Caisse’s BoostCon 2010 talk:

slides: <http://www.objectmodelingdesigns.com/boostcon10/>
video: <http://blip.tv/file/4143337 >

Enjoy!

Machinery, sensors, equipment, client/server communications, even file formats… Parsing and producing communication streams is everywhere you look. Often these tasks are simple or small enough to tempt ad-hoc solutions. The Spirit 2.1 library provides a model that is simple enough to tackle those “quick hacks” and easily scales for full-featured AST generation.

This session will explore real-life experiences with the parser and generator (Qi/Karma) portions of the Spirit library. As we look at various small and medium-sized parsers/generators employed in various products we will establish some “rules-of-thumb” and guidelines for tackling the parser/generator domain with Qi/Karma. The session will end with the implementation of a usable XML parser and a simplified XPath-like node extractor.

The session will include some lecture and a lot of tutorial. Attendees will walk away with the knowledge and tools to begin parsing and generating with Spirit Qi/Karma.

—Michael Caisse

Tagged with:
May ’10 13

Michael Caisse (of Object Modeling Designs), some of you will know him from the Freenode #boost IRC channel, presented his talk about Spirit at BoostCon 2010 last Tuesday. I personally very much like listening to his knowledgeable and entertaining presentations. Apparently many people do so as well, the room he presented in was overfull. People even sat on the floor as all seats were taken. So in case you are interested – here is a link to his slides: Using Spirit V2: Qi and Karma.

Tagged with:
May ’10 11

Finally, yesterday was the day! Joel and I presented the current status of our work related to the ‘Writing a Compiler’ effort. We submitted this talk to BoostCon 2010 and got accepted back in January. Having to present at BoostCon just put a nice pressure onto us to get moving and to start working on the project. I don’t want to go into any detail about the presentation itself. This will be done in future articles to be published after BoostCon. I just wanted to provide a link to the slides for those interested in having a look. Ok, here we go: A Framework for RAD Spirit, grab it while it’s hot!

Tagged with:
May ’10 08

Finally, the long wait and the preparations for BoostCon 2010 are over. The last weeks were dominated by writing the code and creating the slides for our talk ‘A Framework for RAD Spirit‘. Regular readers of this site probably have already wondered why we have been inactive here since mid-March. Well, that is mainly because of preparing for BoostCon turned out to be too time consuming to leave any room for writing posts and articles.

Continue reading »

Tagged with:
Mar ’10 09

Tino Didriksin published yet another speed comparison of different ways to convert an integer into a string (see his blog A howl on the Wind…). And again, Karma turns out to be the leader of the pack by being upto 10 times faster than the other tested methods. This nicely supports our own measurements (see here). Thanks Tino!

Tagged with:
Mar ’10 03

The concept of Spirit’s semantic actions seems to be easy enough to understand as most people new to the library prefer their usage over applying the built-in attribute propagation rules. That is not surprising. The idea of attaching a function to any point of a grammar which is called whenever the corresponding parser matched is straighforward to grasp. Earlier versions of Spirit required a semantic action to conform to a very specific interface. Today’s semantic actions are more flexible and more powerful. Recently, a couple of people asked questions about them. So I decided dedicating this Tip of the Day to the specifics and the usage model of semantic actions in Spirit Qi.

Continue reading »

Tagged with:
Jan ’10 26

A couple of days ago I promised to get back to this topic (if you want to refresh your memory, here is the discussion of those operators in Qi). Today we will discuss Karma’s unary operators ‘!’ and ‘~’. These have very similar semantics as their counterparts in Qi, but as usual, we have to turn things inside out in order to make them fit to output generation.

Continue reading »

Tagged with:
Jan ’10 21

In the previous installment of the ‘Tip of the Day’ I started to talk about some lesser known features related to semantic actions. Today I will highlight some more details. If a semantic action is attached to a component which is part of an expression assigned to a rule (the rule’s right hand side) it is not only possible to access the attributes of the components it is connected with. In addition it is possible to access rule specific values! Sounds interesting? Read on!

Continue reading »

Tagged with:
Jan ’10 19

The concept of semantic actions seems to be quite easy to understand. It appears to be at least easier to grasp than the concept of attribute propagation. This might be because semantic actions have been part of Spirit for almost a decade now. Additionally, with semantic actions data flow control is tightly connected to the component the semantic action is attached to, so the effect is highly localized and easy to spot.

Spirit has some new features related to semantics actions. That’s reason enough to talk about how attributes can be accessed from inside semantic actions.

Continue reading »

Tagged with:
Jan ’10 15

If you read the article about attribute handling for non-terminals (The Magical Power of Attributes in Spirit – Directives and Non-terminals) you might remember that Spirit’s non-terminals (rules and grammars) are somewhat special with regard to their attribute handling. In today’s ‘Tip of the Day’ I would like to revisit this topic as it still seems to be difficult to understand.

Continue reading »

Tagged with:
Jan ’10 13

While looking through the mailing list archives I realized that often the small issues get into our way. Small snippets of information are making the difference. So I decided to start a (more or less regular) series about small tips helping to get your work done while using Spirit. Even if I sloppily call this series ‘Tip of the Day’, I by no means plan to have a tip a day.

This time I’m going to highlight the difference between three different ways to parse or generate a single character: ‘a’, lit(‘a’), and char_(‘a’).

Continue reading »

Tagged with:
Jan ’10 12

Stephan Menzel wrote today on the Boost developer mailing list (see here):

Lacking boost.log we created or own logging class which is basically an as-simple-as-possible Syslog client. (I like to process and accumulate there). It used to be boost.format to assemble the messages which proved slower than log4cxx. With Spirit 2.1 in 1.41 however we changed to use a Karma message generator for this purpose which improved speed dramatically.

Thanks Stephan! We are happy to hear that!

If you have other success stories while using Spirit, we would love to hear about your experience. Just leave a comment below, we happily will write about it.

Tagged with:
preload preload preload