Created
November 15, 2012 18:49
-
-
Save brendanberg/4080423 to your computer and use it in GitHub Desktop.
Revisions
-
brendanberg created this gist
Nov 15, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ /* * Use this at http://pegjs.majda.cz/online * * Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo * - becomes - * Fishy fish fishy fish fish fish fishy fish * * Also, the grammar is recursive, so it could also generate ALL THE FISH. */ start = np:nounphrase " " vp:verbphrase "." { var s = np + " " + vp + "."; return s.charAt(0).toUpperCase() + s.slice(1); } nounphrase = pn:propernoun " " n:noun " " rc:relativeclause { return pn + " " + n + " " + rc; } / pn:propernoun " " n:noun { return pn + " " + n; } verbphrase = v:verb " " np:nounphrase { return v + " " + np; } relativeclause = np:nounphrase " " v:verb { return np + " " + v; } propernoun = "Buffalo" { return "fishy" } noun = "buffalo" { return "fish"; } verb = "buffalo" { return "fish"; }