Aug 04

A customization point is a code construct that the user can leverage to specialize how a particular library action is handled. A common way of implementing this in C++ is to define a template with the default behavior, and let users specialize it for their own types —e.g., std::hash—. This is the story of Spirit X3 and how it lets you specialize customization points without ever leaving your own namespace, sort of…

I Will Always Find You – Tales of C++

Feb 23

Oh, in case anyone wants to follow the development of X3, here are the Github links:

The full attribute mechanism works + basic C++lambda support. I’ve ported one example (calc4.cpp) which parses to an AST. The AST remains the same. Only the way the grammars are written had to change.

For a teaser: here’s GCC times:

SpiritX3: TOTAL :   4.27 secs
Spirit2:  TOTAL :  10.00 secs

Even faster at CT than the first Spirit3 attempt. Runtime speed? I expect it to be faster than Spirit-2. The rules have changed (pun intentional). Now, there’s no longer the need for virtual functions and auto is used extensively. I expect code size to be smaller too because the compiler can generate more efficient code.

Here’s the calculator grammar (based on calc3.cpp):

//  The calculator grammar
namespace calculator_grammar
    using x3::uint_;
    using x3::char_;

    x3::rule<class expression, ast::program> const expression;
    x3::rule<class term, ast::program> const term;
    x3::rule<class factor, ast::operand> const factor;

    auto const expression_def =
        >> *(   (char_('+') >> term)
            |   (char_('-') >> term)

    auto const term_def =
        >> *(   (char_('*') >> factor)
            |   (char_('/') >> factor)

    auto const factor_def =
        |   '(' >> expression >> ')'
        |   (char_('-') >> factor)
        |   (char_('+') >> factor)

    auto const calculator = x3::grammar(
            expression = expression_def,
            term = term_def,
            factor = factor_def

using calculator_grammar::calculator;
Feb 23

My proposal “Inside Spirit X3. Redesigning Boost.Spirit for C++11” has been accepted for presentation at the C++ Now! 2013 in Aspen Colorado. So after a 2 year hiatus, I’m back to Aspen.

Here’s the abstract:

Inside Spirit X3.Redesigning Boost.Spirit for C++11
Joel de Guzman, 2013

The hugely successful BoostCon ’07 ’08, ’09 and ’10 Spirit talks provided walk-through presentations and tutorials on how to use Spirit. This, time, I propose a presentation that will focus on the design and implementation of Spirit. But to add more to the thrill, I will present a major redesign of Spirit from the ground up, taking advantage of the new C++11 features. One important goal of this experimental version of Spirit (named X3) is to bring back the elegant simplicity of “Classic” Spirit, which was somehow lost with the complexity of Spirit-2 primarily due to the lack of important language features that are just starting to appear in C++ compilers. In this 90-minute presentation, I would like to get down and dirty with Modern C++11 code, and along the way, share my experience as well as expose some of C++11’s shortcomings and my wishes for C++1y.

Hope to see you there!

preload preload preload