| | 1 | /* |
| | 2 | * test of part-of-speech lists in grammar definitions |
| | 3 | */ |
| | 4 | |
| | 5 | #include <tads.h> |
| | 6 | #include <gramprod.h> |
| | 7 | #include <tok.h> |
| | 8 | |
| | 9 | dictionary gDict; |
| | 10 | |
| | 11 | dictionary property nounM, nounF, nounN; |
| | 12 | |
| | 13 | bookM: object |
| | 14 | desc = 'book' |
| | 15 | nounM = 'book' |
| | 16 | ; |
| | 17 | |
| | 18 | boxF: object |
| | 19 | desc = 'box' |
| | 20 | nounF = 'box' |
| | 21 | ; |
| | 22 | |
| | 23 | bagN: object |
| | 24 | desc = 'bag' |
| | 25 | nounN = 'bag' |
| | 26 | ; |
| | 27 | |
| | 28 | grammar nounPhrase: <nounM nounF>->noun_ : object |
| | 29 | desc = "nounPhrase<M/F>: noun = <<noun_>>" |
| | 30 | ; |
| | 31 | |
| | 32 | grammar nounPhrase: nounN->noun_ : object |
| | 33 | desc = "nounPhrase<N>: noun = <<noun_>>" |
| | 34 | ; |
| | 35 | |
| | 36 | main(args) |
| | 37 | { |
| | 38 | "Enter an empty line to quit.\b"; |
| | 39 | |
| | 40 | /* keep going until done */ |
| | 41 | for (;;) |
| | 42 | { |
| | 43 | local str; |
| | 44 | local match; |
| | 45 | |
| | 46 | /* read a line */ |
| | 47 | "Type a noun: "; |
| | 48 | str = inputLine(); |
| | 49 | |
| | 50 | /* if it's empty, quit */ |
| | 51 | if (str == '' || str == nil) |
| | 52 | break; |
| | 53 | |
| | 54 | /* parse it */ |
| | 55 | match = nounPhrase.parseTokens(Tokenizer.tokenize(str), gDict); |
| | 56 | |
| | 57 | /* show any matches */ |
| | 58 | foreach (local cur in match) |
| | 59 | { |
| | 60 | cur.desc; |
| | 61 | "\n"; |
| | 62 | } |
| | 63 | } |
| | 64 | } |
| | 65 | |