Jan 31

Most questions on the main Spirit mailing list are centered around attributes and how to correctly utilize Spirit’s attribute propagation rules. We discussed the related basics in several posts already, but many people still have problems to understand the rules. Somebody recently asked on the mailing list whether it would be possible to print the attribute type exposed by an arbitrary parser expression. I answered by posting a sketchy code snippet (see here), but afterwards I realized it might be a good topic for yet another ‘Tip of the Day’.

Continue reading »

GD Star Rating
loading...
Tagged with:
Jan 28

After writing about local variables for rules here I would like to get back to some information I have had lying around for some time already. Today’s topic seems to be a nice fit as porting the dynamic parsers from Spirit.Classic requires to utilize local variables. This allows me to give you some more examples for this facility.

Previous versions of Spirit, which are the versions we refer to as Spirit.Classic today, implemented special dynamic parsers allowing to insert control statements into the parsing process (such as if_p, while_p, and for_p). These dynamic parsers are not available anymore in Qi. But it is easy enough to achieve the same behavior using existing Qi components. This ‘Tip of the Day’ describes those techniques, which have been developed and contributed by Carl Barron. Thanks Carl!

Continue reading »

GD Star Rating
loading...
Tagged with:
Jan 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 »

GD Star Rating
loading...
Tagged with:
Jan 25

Starting with Spirit V2 we added a module for generating code aimed at the lexical analysis of the input: Spirit.Lex (a lexer module, also called scanner). Lexical analysis is the process of preprocessing the stream of input characters and separating it into strings called tokens, most of the time delimited by whitespace. Most compiler texts start here, and devote several chapters to discussing various ways to build scanners. Spirit.Lex is a library built to take care of the complexities of creating a lexer for your grammar.

We know the documentation of Spirit.Lex is not complete yet. So I will write  more about it here from now on to fill in the missing pieces and to show a couple of tricks demonstrating its best usage.

Continue reading »

GD Star Rating
loading...
Tagged with:
Jan 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 »

GD Star Rating
loading...
Tagged with:
Jan 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 »

GD Star Rating
loading...
Tagged with:
Jan 17

The Freenet #boost IRC channel amazes me every day with the amount of interest Spirit is getting from a lot of people. Thanks to everyone over there! But the best is those people are asking many interesting questions allowing me to come up with yet another Tip of the Day.

Today’s question has been asked by @psicode: “What is the difference between the components created by the unary operators ‘!’ and ‘~’?”. As the semantics of those operators are slightly dissimilar in Qi and Karma, I will talk about them separately. I will write about the Qi operators today and about the corresponding Karma operators in one of the next installments.

Continue reading »

GD Star Rating
loading...
Tagged with:
Jan 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 »

GD Star Rating
loading...
Tagged with:
Jan 14

Over at the Freenet #boost IRC channel somebody (I think it was @VeXocide) suggested to write a ‘Tip of the Day’ about the Qi directive raw[]. I was told this ‘was a major stumbling stone’ while learning Qi. I always appreciate to get suggestions for articles, so here we go…

Continue reading »

GD Star Rating
loading...
Tagged with:
Jan 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 »

GD Star Rating
loading...
Tagged with:
Jan 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.

GD Star Rating
loading...
Tagged with:
Jan 05

We got many questions how to parse data which has to be accessed using a standard input stream (usually a std::istream) without having to read all of the data into memory first.

The standard way of iterating over a stream would be to wrap it into a std::istream_iterator, but unfortunately this is not possible. Qi requires iterators to be at least forward iterators, while the std::istream_iterator is an input iterator only. To overcome this limitation Spirit V2.2 (the next version of Spirit, to be released with Boost V1.42) will implement a new iterator.

Continue reading »

GD Star Rating
loading...
Tagged with:
Jan 02

Thank you all for your warm feedback on the “Build a Compiler” post. It seems this has become very popular indeed. I guess it’s time to start. Your overwhelming feedback and comments is enough motivation to carry on with the article series.

In general, an imperative OO language seems to be the way to go. It’s not surprising that C++ is very popular. People want a C++ parser! Barring that, due to complexity, a subset or a sanitized/re-syntaxed C++ (e.g. SPECS) is also a popular request. Go is also quite popular. That language indeed looks good and modern. FP, especially LISP/Scheme and even Haskell(!) is also quite popular. And hey: Javascript! and Python! Life would not be complete without these fun languages:-).
Continue reading »

GD Star Rating
loading...
Jan 02

The year 2009 came to an end. This is reason enough to have a look at the statistics collected for our new website and to publish a list of the most popular posts and articles. I will use the number of hits as a metric of popularity. But since we created this new website only in November all statistics will be based on the hits collected over the last two month only.

The most popular post was Joel’s note about his plans to Build a Compiler. This post got the most attention in terms of comments as well. Many people seem to be interested in seeing how to utilize Spirit for more complex things.

The second most popular article was The Magical Power of Attributes – Primitives, which is a first in a series of three articles highlighting Spirit’s new capabilities related to attributes. I’m planning to continue to write this style of articles in the future, so their popularity is a big encouragement for me.

The third in the row of popular articles was the list of Who is using Spirit. As it turns out, Spirit gained quite some track record in the community over the last years. We are very proud of this impressive list and would like to thank everybody for their support! And, by the way, if you want to see your project in this list, just leave a comment there, we will happily add the information.

I’m very happy to see that the articles showing how to use Spirit for specific tasks draw a lot of attention as well. The next three in the row of popular articles are: Parsing a List of Key-Value Pairs Using Spirit.Qi, Creating Your Own Parser Component for Spirit.Qi, and Generate Escaped String Output Using Spirit.Karma. It seems that’s definitely something we will have to continue in the future.

Again, on behalf of Joel and myself, let me express our gratitude for all the support we received over the last time. We have a lot of ideas how to improve Spirit and we will need your help in the future. Stay tuned!

Happy new year to you all!

GD Star Rating
loading...
preload preload preload