--[[
Input (grammar) looks like this:
Apology ::= my (cat|mouse|monkey) ate my homework.
Apology ::= our (basement|attic|third floor) collapsed from an overload of school books.
]]
-- Put the grammar into array "rules".
rules = splitIntoLines(getSnippet("#229"))
-- Choose one of the rules (randomly).
rule = chooseOne(rules)
-- Parse rule: Apology ::= <bla>
bla = match(rule, "Apology ::= <bla>")
-- Parse bla into:
-- #1 (...)
-- #2 everything else
i = rule:find("([^)]*)"
With every s in #1 do:
-- Split inner part of s at "|" into "options".
options = split(inner, "|")
-- Choose one of the options (randomly).
option = chooseOne(options)
-- Replace s with option.
-- Print bla (with the replacements made).
print(join(bla))Began life as a copy of #231
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
2 comment(s) hidden. show
| Recognizer | Recognition Result | Visualize | Recalc |
|---|---|---|---|
| #308 | 782 | [visualize] |
| Snippet ID: | #233 |
| Snippet name: | Executor for apology generator (unfinished) |
| Eternal ID of this version: | #233/1 |
| Text MD5: | 039d1e16fe5c7c1c7926bb407a4a6954 |
| Author: | stefan |
| Category: | Apology generators |
| Type: | Lua code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2014-02-06 13:54:27 |
| Source code size: | 782 bytes / 31 lines |
| Pitched / IR pitched: | Yes / Yes |
| Views / Downloads: | 1560 / 285 |
| Referenced in: | [show references] |