Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. string getSentence(production p, map<string, Definition>& grammar){
  2. string result;
  3. for (Production::iterator curr = p.begin(); curr != p.end(); ++curr) {
  4. if(curr!='<'){
  5. result+=curr;
  6. }else{
  7. string prod;
  8. while(curr!='>'){
  9. ++curr;
  10. prod+=curr;
  11. }
  12. result+=getSentence(grammar.get(prod).getRandomProduction(), grammar);
  13. }
  14. }
  15. return result;
  16. }
  17. void formSentence(map<string, Definition>& grammar){
  18. production p = grammar.get("<start>").getRandomProduction();
  19. for(int i=0; i < 3; i++) cout << getSentence(p,grammar) << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement