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 »

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 »

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 »

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 »

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 »

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 »

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 »

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.

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 »

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 »

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!

Dec 21

I added a page for FAQ entries. This page will contain FAQ entries which will eventually be incorporated into the FAQ section of the documentation.

See the page here.

Dec 21

In the previous two installments of this article series (The Magical Power of Attributes in Spirit – Primitives and The Magical Power of Attributes in Spirit – Operators) we talked about the attribute handling in different constructs utilized to build parsers and generators with Spirit. We will continue this walkthrough while touching on the remaining parts: directives and non-terminals

See full article here.

Tagged with:
Dec 15

How about some trivia…

So you know BNF (Backus-Naur Form or originally Backus Normal Form) and EBNF (Extended Backus-Naur Form). But did you know Panini’s grammar? It defined Sanskrit using a variety of formal techniques including recursion, transformations, and metarules. That was around 500 B.C.!

See this link. And this.

Dec 14

Each operator implements its own set of attribute propagation rules. These rules define the synthesized attributes of Qi expressions and the consumed attributes of Karma expressions. As we have seen already, it is very important to understand how the synthesized and consumed attributes are formed. Parsers and generators are most elegant and efficient if they are tightly integrated with your data structures, and learning to match those to the attributes is crucial to being able to apply Spirit for your own needs.

See full article here.

Tagged with:
preload preload preload