Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string getSentence(production p, map<string, Definition>& grammar){
- string result;
- for (Production::iterator curr = p.begin(); curr != p.end(); ++curr) {
- if(curr!='<'){
- result+=curr;
- }else{
- string prod;
- while(curr!='>'){
- ++curr;
- prod+=curr;
- }
- result+=getSentence(grammar.get(prod).getRandomProduction(), grammar);
- }
- }
- return result;
- }
- void formSentence(map<string, Definition>& grammar){
- production p = grammar.get("<start>").getRandomProduction();
- for(int i=0; i < 3; i++) cout << getSentence(p,grammar) << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement