--[[
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
| ID | Author/Program | Comment | Date | |
|---|---|---|---|---|
| 688 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { --[[ 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)) }} | 2015-08-19 08:42:32 | delete |
| 686 | #1000604 (pitcher) | 2015-08-18 00:07:22 |
| 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: | 1557 / 285 |
| Referenced in: | #3000189 - Answer for stefanreich(>> t bla) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |