1 | --[[ |
2 | Input (grammar) looks like this: |
3 | |
4 | Apology ::= my (cat|mouse|monkey) ate my homework. |
5 | Apology ::= our (basement|attic|third floor) collapsed from an overload of school books. |
6 | ]] |
7 | |
8 | -- Put the grammar into array "rules". |
9 | rules = splitIntoLines(getSnippet("#229"))
|
10 | |
11 | -- Choose one of the rules (randomly). |
12 | rule = chooseOne(rules) |
13 | |
14 | -- Parse rule: Apology ::= <bla> |
15 | bla = match(rule, "Apology ::= <bla>") |
16 | |
17 | -- Parse bla into: |
18 | -- #1 (...) |
19 | -- #2 everything else |
20 | |
21 | i = rule:find("([^)]*)"
|
22 | |
23 | With every s in #1 do: |
24 | -- Split inner part of s at "|" into "options". |
25 | options = split(inner, "|") |
26 | -- Choose one of the options (randomly). |
27 | option = chooseOne(options) |
28 | -- Replace s with option. |
29 | |
30 | -- Print bla (with the replacements made). |
31 | 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: | 1700 / 299 |
| Referenced in: | [show references] |