void gen_aux(const Grammar& g, const string& word, vector<string>& ret, const int depth) { if (depth > 3) { return; } if (!bracketed(word)) { ret.push_back(word); } else { // locate rule that corresponds to word Grammar::const_iterator it = g.find(word); if (it == g.end()) { throw logic_error("empty rule"); } // fetch the set of possible rules const Rule_collection& c = it->second; int index = nrand(c.size()); const Rule& r = c[index]; // recursively expand the selected rule for (Rule::const_iterator i = r.begin(); i != r.end(); ++i) { gen_aux(g, *i, ret, depth + 1); } } }
void gen_aux(const Grammar& g, const string& word, vector<string>& ret) { if (!bracketed(word)) { ret.push_back(word); } else { // locate the rule that corresponds to word Grammar::const_iterator it = g.find(word); if (it == g.end()) throw logic_error("empty rule"); // fetch the set of possible rules const Rule_collection& c = it->second; // from which we select one at random const Rule& r = c[nrand(c.size())]; // recursively expand the selected rule for (Rule::const_iterator i = r.begin(); i != r.end(); ++i) gen_aux(g, *i, ret); } }
void expand_aux (const Grammar &g, const std::string &word, TokenStack &result) { Grammar::const_iterator it = g.find (word); if (g.end() != it) { const RuleCollection &rc = it->second; const Rule &r = rc[nrand(rc.size())]; for (int i = r.size() - 1; i > -1; --i) { result.push(r[i]); } } }
void gen_aux(const Grammar& g, const std::string& word, std::list<std::string>& ret) { if(!bracketed(word)) { ret.push_back(word); } else { Grammar::const_iterator it = g.find(word); if(it == g.end()) throw std::logic_error("empty rule"); const Rule_collection& c = it->second; const Rule& r = c[nrand(c.size())]; for(Rule::const_iterator i = r.begin(); i != r.end(); ++i) gen_aux(g, *i, ret); } }
void gen_aux (const Grammar &g, const std::string &word, std::vector<std::string> &result) { if (!bracketed (word)) { result.push_back (word); } else { Grammar::const_iterator it = g.find (word); if (g.end() == it) throw std::logic_error ("empty grammar rule"); const RuleCollection &rc = it->second; const Rule &r = rc[nrand(rc.size())]; for (Rule::const_iterator r_it = r.begin(); r_it != r.end(); ++r_it) gen_aux (g, *r_it, result); } }
void gen_aux(const Grammar& g, const std::string& word, std::vector<std::string>& ret) { if (!bracketed(word)) { ret.push_back(word); } else { Grammar::const_iterator it = g.find(word); if (it == g.end()) { std::logic_error("Rule is empty"); } // get rule collection from grammar const Rule_collection& c = it->second; // select a new rule from collection at random const Rule& r = c[nrand(c.size())]; // expand rule for (Rule::const_iterator i = r.begin(); i != r.end(); ++i) { gen_aux(g, *i, ret); } } }