From: TONGARI <ton...@gm...> - 2011-01-15 18:06:09
|
2011/1/15 TONGARI <ton...@gm...> > Other ideas? > > abhay, have you tried the Nabialek trick? Instead of using those chained alternatives, using that trick may do much better. The article about that is even updated with some optimization: http://boost-spirit.com/home/articles/qi-example/nabialek-trick/ I'd like to suggest in this case, you could: 0) use symbol_table that maps keywords(your function names) to the rules e.g. qi::symbols<char, rule_type*> 1) in each FunctionN.cpp void register_fN_rule(symbol_table& sym) { static rule_type rule; // rule = ... sym.add("fN", &rule); } 2) the grammar may look like: struct grammar : qi::grammar<iterator_type, qi::locals<rule_type*>, standard::space_type> { grammar() : grammar::base_type(start) { register_f1_rule(sym); ... register_f40_rule(sym); start = sym[qi::_a = qi::_1] >> qi::lazy(*qi::_a); } qi::rule<iterator_type, qi::locals<rule_type*>, standard::space_type> start; symbol_table sym; }; HTH |