boost::spirit Library Usage Example

Annotation

Tasks of lexical, syntax and semantic analysis come up at the every day programmers' practice quite often. Most often a plain symbols stream plays a role of an input stream. A typical example of a similar task is reading a textual configuration file of some application. That kind of tasks is usually solved with the help of tools like flex and yacc. However there is more elegant solution for C++. The boost::spirit library simplifies the mentioned analysis stages considerably. The result C++ code gets compact and easy to make further changes.

The article describes an example of the library usage. The selected example implies all three mentioned analysis stages and their results are passed to a virtual machine for the execution. The final solution looks simple and suitable for future reuse.




The translator and and the virtual machine code was tested with gcc 3.4.2 and boost 1.33.0 on Linux. Most probably it will work on any other platform which is supported by boost.


Last Updated: December 8, 2005