
Korcan Hussein wrote:
"Larry Evans" <cppljevans@cox-internet.com> wrote in message news:435B9E00.3030607@cox-internet.com...
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 http://www.boost.org/libs/spirit/doc/subrules.html carefully. Read below the lines that you have quoted. Those lines you quoted were there just to explain the problems of type-erased rules. 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)); ? Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net