tags:

views:

30

answers:

1

I started using spirit yesterday. I have to write a parser for a small language and to form an intermediate data structure. I followed the Pascal Parser example at Boost Repository. This example is good as it supports easy debugging. The example uses Classic Spirit.

  • Should I translate to use Qi (I have not faced any issues till now with respect to Spirit)?
  • Is there a simple example for such a conversion? I am mainly using classic::grammar class right now as in the example.
+1  A: 

If you start a new project I definitely suggest to stick with Spirit.Qi. Spirit.Classic is in maintenance mode only while Spirit.Qi is being actively developed. In addition, the parsers generated by Qi are a lot faster than the older ones.

The conversion from Spirit.Classic to Spirit.Qi is not straightforward as the API has changed. There is some getting started documentation on this, though. But if you start with a new project this shouldn't matter too much as you have to get accustomed with a new library in any case.

So I'd suggest you try to read the introductory documentation, look at the examples and tests which come with Spirit, and most importantly try to understand how Spirit handles the parser attributes. From my experience, parser attributes and their propagation rules are the most difficult concept to understand, while at the same time they are crucial to Spirit's way of doing things, and they make Spirit as powerful and flexible as it is.

hkaiser
I have read the introductory documentation. The ready-made example of the Pascal parser was also very useful, particularly the debug mode. I have learnt a bit about the propagation rules and parser attributes by hit-and-trial while coding up my own parser by modifying the Pascal parser. Specifically I learnt that the alternative operator takes the first shortcut that succeeds and does not backtrack. But the problem is that the Pascal parser uses Spirit.Classic. I would like to work in Spirit.Qi but it would be highly useful if there were an example similar to the Pascal parser for Qi.
Amit Kumar
On a second look, I think the porting guide would be quite useful: boost.org/doc/libs/1_43_0/libs/spirit/doc/html/… I will try to contribute a Qi-based Pascal parser example. By the way, big thanks for your immense contributions to Spirit.
Amit Kumar