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 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 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:
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.

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

GD Star Rating
loading...
Tagged with:
Dec 11

Spirit V2.1 has been released only a couple of weeks ago. The first feedback we have gotten so far was overwhelming! Many people seem to quickly understand the concepts of the new library, being able to apply its power to their needs. We try to follow people’s comments and watch for reported problems. There is one theme recurring over and over again: attributes. This new (for Spirit) concept turns out to be the most difficult idea to understand, especially for somebody starting to work with the library.

See full article here.

GD Star Rating
loading...
Tagged with:
Nov 20

Creating Your Own Parser Component for Spirit.Qi

By Hartmut Kaiser Qi Example Comments Off on Creating Your Own Parser Component for Spirit.Qi

Several people have been asking the question of how it would be possible to access the current iterator position from a semantic action. Different solutions have been proposed, all of them somehow abusing the predefined Qi directive raw[] which normally exposes as its attribute the pair of iterators pointing to the range in the input stream matched by the embedded parser. I thought this to be a nice incentive to write about how you can create your own parser components.

See full article here.

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

Zero to 60 MPH in 2 seconds!

By Joel de Guzman Qi Example Comments Off on Zero to 60 MPH in 2 seconds!

Wanna make a blazingly fast rule? Use BOOST_AUTO! Check it out here. The code defines a named rule using C++0x auto when available and falls back to some template wizardry on older compilers.

See full article here.

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

Nabialek trick

By Joel de Guzman Qi Example Comments Off on Nabialek trick

This sample is a port of the original “Nabialek trick” from classic Spirit.

See full article here.

GD Star Rating
loading...
Tagged with:
preload preload preload