
On 10/23/2005 12:12 PM, Korcan Hussein wrote: [snip]
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)); [snip] I'll get back to you on that one, for the time being i have uploaded the example i have been writing about, it is in the vault here: http://www.boost-consulting.com/vault/index.php?action=downloadfile&filename=expr_test.cpp&directory=Template%20Metaprogramming&
In the example program you should see something similar, take note however this isn't a library in any form it is just a (very) rough example of the technique, it has (as of yet) not been fully generalized but it should not be to diffcult. It should be enough to give people an idea to discuss about and consider a possibility.
Hopefully, the file: proto_static_disp.cpp will also generate some ideas. AFAICT, the arith_expr_gram typedef in that file contains all the grammar (which is recursive) and *maybe* could be further developed to eliminate dynamic dispatching. Of course, I've only compiled it and not yet tried to parse anything with it. It's also not readable, but I'm thinking that maybe the proposed typeof and << and | and spirit operators could be used to replace the 2nd part of the mpl::pair's in the mpl::map.