//a simple program for parsing and creating a new sentence out of a given cfg
var store = {
"nounphrase" : "<noun> | <adj> <adj> <noun> | super <nounphrase>",
"noun" : "apple | pear | mailman",
"adj" : "smelly | chartreuse | enormous"
};
function parse(str, store){
  str = str.trim();
  if(store[str]){
  str = store[str];
  }
  var tokens = str.split("|");
  var obj = tokens[Math.floor(Math.random()*tokens.length)];
  var words = obj.split(" ");
  var res = "";
  words.forEach(function(w){
    if(w[0] == '<'){
     res += parse(w.substring(1,w.length-1), store)+" ";
    } else {
     res += w.trim()+" ";
    }
  });
 return res.trim();
}
parse(store.nounphrase, store);

@@ -90,148 +90,366 @@
  %7B%0A%22
-nounphrase%22 : %22%3Cnoun%3E %7C %3Cadj%3E %3Cadj%3E %3Cnoun%3E %7C super %3Cnounphrase%3E
+full%22 : %22%3Cadj%3E %3Chero%3E %3Cverb%3E %3Cvadj%3E %3Cvillain%3E %7C hulk smash little %3Cvillain%3E %7C %3Chero%3E is %3Cadj%3E %7C %3Cvillain%3E is %3Cvadj%3E %22,%0A%22hero%22 : %22batman %7C superman %7C spiderman %7C ironman %7C thor
 %22,
+ 
 %0A%22
-noun%22 : %22apple %7C pear %7C mailman%22,%0A%22adj%22 : %22smelly %7C chartreuse %7C enormous
+villain%22 : %22doom %7C darkseid %7C joker %7C loki %7C thanos%22,%0A%22verb%22 : %22hits %7C kicks %7C punches %7C hits%22,%0A%22adj%22 : %22quick %7C nimble %7C strong %7C smart%22,%0A%22vadj%22 : %22stupid %7C cunning %7C evil %7C mad
 %22%0A%7D;
@@ -873,18 +873,12 @@
 ore.
-nounphrase
+full
 , st

Update context_free_grammer_test.js