Oh, in case anyone wants to follow the development of X3, here are the Github links:
https://github.com/djowel/spirit_x3
https://github.com/djowel/spirit_x3.git
git@github.com:djowel/spirit_x3.git
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 =
term
>> *( (char_('+') >> term)
| (char_('-') >> term)
)
;
auto const term_def =
factor
>> *( (char_('*') >> factor)
| (char_('/') >> factor)
)
;
auto const factor_def =
uint_
| '(' >> expression >> ')'
| (char_('-') >> factor)
| (char_('+') >> factor)
;
auto const calculator = x3::grammar(
expression = expression_def,
term = term_def,
factor = factor_def
);
}
using calculator_grammar::calculator;
Recent Comments