Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2005-10-23 10:15:38

Korcan Hussein wrote:
> "Larry Evans" <cppljevans_at_[hidden]> wrote in message
>>On 10/22/2005 06:58 AM, Larry Evans wrote:
>>Are you suggesting this as an alternative to Spirit subrules?
> Doesn't need to replace subrules but could be an alternative implementation
> for them, if you read the part:
> [qoute]
> ... It might not be apparent but behind the scenes, plain rules are actually
> implemented using a pointer to a runtime polymorphic abstract class that
> holds the dynamic type of the parser assigned to it. When a Spirit
> expression is assigned to a rule, its type is encapsulated in a concrete
> subclass of the abstract class. A virtual parse function delegates the
> parsing to the encapsulated object.
> Rules have drawbacks though:
> It is coupled to a specific scanner type. The rule is tied to a specific
> scanner [see The Scanner Business].
> The rule's parse member function has a virtual function call overhead that
> cannot be inlined.
> [/quote]

That quote pertains to (type-erased rules) not subrules.
Subrules in Spirit are completely static. No type erasure.
Please read the
carefully. Read below the lines that you have quoted. Those lines
you quoted were there just to explain the problems of type-erased

I'm quite interested if you have a better alternative. For example,
how do you write the Spirit calculator using your scheme:

     rule<> group, factor, term, expression;

     group = '(' >> expression >> ')';
     factor = integer | group;
     term = factor >> *(('*' >> factor) | ('/' >> factor));
     expression = term >> *(('+' >> term) | ('-' >> term));



Joel de Guzman

Boost list run by bdawes at, gregod at, cpdaniel at, john at