| 1 |
/* |
| 2 |
* vocabulary test |
| 3 |
*/ |
| 4 |
|
| 5 |
#include "tads.h" |
| 6 |
#include "t3.h" |
| 7 |
#include "dict.h" |
| 8 |
|
| 9 |
dictionary G_dict; |
| 10 |
dictionary property noun, adjective, plural; |
| 11 |
|
| 12 |
class Item: object |
| 13 |
; |
| 14 |
|
| 15 |
class Book: Item |
| 16 |
noun = 'book' 'booklet' 'volume' |
| 17 |
plural = 'books' 'booklets' 'volumes' |
| 18 |
sdesc = "book" |
| 19 |
adjective = 'musty' |
| 20 |
; |
| 21 |
|
| 22 |
class LightItem: Item |
| 23 |
noun = 'light' |
| 24 |
; |
| 25 |
|
| 26 |
modify Book |
| 27 |
noun = 'tome' |
| 28 |
replace plural = 'tomes' |
| 29 |
; |
| 30 |
|
| 31 |
redBook: Book |
| 32 |
adjective = 'red' |
| 33 |
sdesc = "red_book" |
| 34 |
; |
| 35 |
|
| 36 |
lightSwitch: SwitchItem, LightItem |
| 37 |
sdesc = "light_switch" |
| 38 |
; |
| 39 |
|
| 40 |
main(args) |
| 41 |
{ |
| 42 |
"noun 'book': <<sayList(G_dict.findWord('book', &noun))>>\n"; |
| 43 |
"noun 'booklet': <<sayList(G_dict.findWord('booklet', &noun))>>\n"; |
| 44 |
"plural 'books': <<sayList(G_dict.findWord('books', &plural))>>\n"; |
| 45 |
"noun 'tome': <<sayList(G_dict.findWord('tome', &noun))>>\n"; |
| 46 |
"plural 'tomes': <<sayList(G_dict.findWord('tomes', &plural))>>\n"; |
| 47 |
"adjective 'red': <<sayList(G_dict.findWord('red', &adjective))>>\n"; |
| 48 |
"adjective 'musty': <<sayList(G_dict.findWord('musty', &adjective))>>\n"; |
| 49 |
"\b"; |
| 50 |
|
| 51 |
"redBook.noun: <<sayStrList(redBook.noun)>>\n"; |
| 52 |
"blueBook.noun: <<sayStrList(blueBook.noun)>>\n"; |
| 53 |
"blueBook.plural: <<sayStrList(blueBook.plural)>>\n"; |
| 54 |
"redBook.adjective: <<sayStrList(redBook.adjective)>>\n"; |
| 55 |
"blueBook.adjective: <<sayStrList(blueBook.adjective)>>\n"; |
| 56 |
"blueBook.plural: <<sayStrList(blueBook.plural)>>\n"; |
| 57 |
"\b"; |
| 58 |
|
| 59 |
"noun 'switch': <<sayList(G_dict.findWord('switch', &noun))>>\n"; |
| 60 |
"noun 'light': <<sayList(G_dict.findWord('light', &noun))>>\n"; |
| 61 |
"lightSwitch.noun: <<sayStrList(lightSwitch.noun)>>\n"; |
| 62 |
"lightSwitch.adjective: <<sayStrList(lightSwitch.adjective)>>\n"; |
| 63 |
"\b"; |
| 64 |
|
| 65 |
"Iterating over each dictionary entry...\n"; |
| 66 |
G_dict.forEachWord({ obj, str, prop: |
| 67 |
"\t<<str>>: <<obj.sdesc>> |
| 68 |
<<reflectionServices.valToSymbol(prop)>>\n"}); |
| 69 |
} |
| 70 |
|
| 71 |
sayList(lst) |
| 72 |
{ |
| 73 |
if (lst == nil) |
| 74 |
{ |
| 75 |
"nil"; |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
"["; |
| 80 |
for (local i = 1, local len = lst.length() ; i <= len ; i += 2) |
| 81 |
{ |
| 82 |
if (i > 1) |
| 83 |
", "; |
| 84 |
lst[i].sdesc; |
| 85 |
} |
| 86 |
"]"; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
sayStrList(lst) |
| 91 |
{ |
| 92 |
if (lst == nil) |
| 93 |
{ |
| 94 |
"nil"; |
| 95 |
} |
| 96 |
else |
| 97 |
{ |
| 98 |
"["; |
| 99 |
for (local i = 1, local len = lst.length() ; i <= len ; ++i) |
| 100 |
{ |
| 101 |
if (i > 1) |
| 102 |
", "; |
| 103 |
tadsSay(lst[i]); |
| 104 |
} |
| 105 |
"]"; |
| 106 |
} |
| 107 |
} |
| 108 |
|