<offtopic>
On Tue, Oct 20, 2009 at 2:04 PM, Sean Chittenden <[email protected]> wrote:
> This is completely off topic, but you say spirit > ANTLR. By that I'm
> assuming you mean bison or lemon are slower at runtime than spirit?
> Very interested in this. :) -sc
Yes. And if there is ever anything that you find faster at something
then Spirit2.1+ is, tell us and we will fix Spirit2 to be faster on
that as well. :)
Spirit2.1 is actually a good bit faster then ANTLR, and if can do
almost everything that ANTLR can. The 'almost' part comes from that,
for speed reasons, Spirit requires a start and end iterator and is not
capable of incremental parsing, other then that it should be able to
do everything ANTLR can and a great deal more. Spirit2.1 even parses
simple integers faster then itoa, everything is focused on speed. The
way it works is that your grammar, for example this:
struct myStruct { double d; int i; };
rule<IteratorType, myStruct()> myRule = double_ >> ',' >> int_;
string myString("3.14,42");
myStruct result;
parse(myString.begin(),myString.end(),myRule,result);
The "double_ >> ',' >> int_" part is not the actual parser, it builds
a type tree and the type is stored into rule, without semantic
expressions this step is really fast, and only needs to be done once
per program run (fine to put at global or thread-local scope for
example), and this is where all the real work is.
The parse function then takes that type tree and recurses down it to
parse the string, and yes the result will be result.d==3.14 and
result.i==42. You can also specify skippers (to skip whitespace,
comments, etc...), semantic actions (to do any other arbitrary things
then just fill a data structure), can create your own terminals as
well (the int_ is a terminal, and yes, it is really easy to create
your own terminals, Spirit2.1 comes with a lot, and it includes a
repository for a lot of other third-party ones that have been
donated).
But for example, the "double_ >> ',' >> int_" create a type tree that
returns a type of tuple<double,int>, the struct myStruct can be made
compatible with it by either adding it to the Boost.Fusion overloads,
or using the new type resolving system in Spirit2.2 (in trunk right
now, to be fully released at Boost 1.42) that allows you to resolve
anything to anything.
And there are a few included benchmarks included too. I need to
finish prettying up the ANTLR benchmarks I did and submit those too.
And yes, Spirit works with any forward-iterator compatible iterator,
and for iterators that are input iterators (not forward, like cin is
an input-iterator), then Spirit2.1 includes a highly efficient
multi-pass iterator that converts an input iterator to a forward
iterator.
</offtopic>
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest