|
a self-optimizing alternative parser: msg#00025parsers.spirit.devel
Hi, I find this idea so great, that I hope it's worth a forward and some more thoughts... It's inspired by Elviin's post and Carl Barron's response on spirit.general lately (conversation and names got cut). Tobias Schwinger wrote:
The information in this last paragraph might be too dense and maybe some code is useful to illustrate what I'm talking about: template<typename Parser, typename Scanner> bool parse_function(void* parser, Scanner & scan) { return static_cast<Parser*>(parser)->parse(scan).hit; } Now the expression "& parse_function<Parser,Scanner>" gives us a function pointer of the type "bool(*)(void*,Scanner & scan)". A probability parser instance would use a fixed scanner type (given as template argument, just like "rule") so the scanner type is known and the parser type vanishes, so parsers can be stored as a void pointer (this technique must be applied again for destruction and maybe copying, I don't bother here for the sake of simplicity). In Spirit-2 (based on the information that there is so far) we're talking about iterators instead of scanners (it makes the client interface more convenient). Still, fixed scanner type or fixed iterator type -- it's still somewhat inconvenient. Further there's one dynamic call that won't go away. Given we have a tuple of parsers we can use a (runtime) index instead of a void pointer to as a reference to a parser and code like that: switch(parser_index) { case 0: return at_c<Parsers,0>(parsers)->parse [...] case 1: return at_c<Parsers,1>(parsers)->parse [...] case 2: return at_c<Parsers,2>(parsers)->parse [...] // [...] } // naive code for illustration (fusion::accumulate // allows us to implement a scalable version) The nicest thing about it is: we don't have to hard-wire scanner or iterator. For a small number of component parsers we might have more efficient dispatch (especially on modern CPUs with BTC), however, if the number of parsers gets too high, the dynamic call O(1) becomes faster than the cascade of conditional branches O(N). Since the O(1) version implies a less convenient interface we should push things even further by bringing the dispatcher into a tree structure to have O(log N) so things still work well with comparatively many component parsers. Comments welcome! Regards, Tobias ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Fusion-ifying proto parse trees: 00025, Eric Niebler |
|---|---|
| Next by Date: | further thoughts on adaptive parse algorithms: 00025, Tobias Schwinger |
| Previous by Thread: | Fusion-V2-ifying proto parse treesi: 00025, Eric Niebler |
| Next by Thread: | Re: a self-optimizing alternative parser: 00025, Tobias Schwinger |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | Mail Home | sitemap | FAQ | advertise |