| | 1 | /* |
| | 2 | * A simple parser for a few phrases |
| | 3 | */ |
| | 4 | |
| | 5 | #include "tads.h" |
| | 6 | #include "t3.h" |
| | 7 | #include "dict.h" |
| | 8 | #include "gramprod.h" |
| | 9 | |
| | 10 | grammar command: predicate->pred_ cmdTerminator * |
| | 11 | debugPrint(level) |
| | 12 | { indent(level); "command pred:\n"; pred_.debugPrint(level+1); } |
| | 13 | ; |
| | 14 | |
| | 15 | grammar cmdTerminator: 'then' | '.' | '!' | ';' | '?' |
| | 16 | | 'and' 'then' | 'and' |
| | 17 | | ',' 'then' | ',' 'and' 'then' | ',' 'and' | ',' : object |
| | 18 | ; |
| | 19 | |
| | 20 | grammar predicate: 'say' tokString->str_ : object |
| | 21 | debugPrint(level) |
| | 22 | { indent(level); "predicate tadsSay(str_ = <<str_>>)\n"; } |
| | 23 | ; |
| | 24 | |
| | 25 | grammar predicate: 'take' nounPhrase->np_ : object |
| | 26 | debugPrint(level) |
| | 27 | { indent(level); "predicate take np:\n"; np_.debugPrint(level+1); } |
| | 28 | ; |
| | 29 | |
| | 30 | grammar predicate: 'give' nounPhrase->dobj_ 'to' nounPhrase->iobj_ |
| | 31 | | 'give' nounPhrase->iobj_ nounPhrase->dobj_ : object |
| | 32 | debugPrint(level) |
| | 33 | { |
| | 34 | indent(level); |
| | 35 | "predicate give dobj, iobj:\n"; |
| | 36 | dobj_.debugPrint(level+1); |
| | 37 | iobj_.debugPrint(level+1); |
| | 38 | } |
| | 39 | ; |
| | 40 | |
| | 41 | grammar nounPhrase: noun->noun_ : object |
| | 42 | debugPrint(level) |
| | 43 | { indent(level); "nounPhrase(noun = <<noun_>>)\n"; } |
| | 44 | ; |
| | 45 | |
| | 46 | grammar nounPhrase: adjective->adj_ nounPhrase->np_ : object |
| | 47 | debugPrint(level) |
| | 48 | { |
| | 49 | indent(level); |
| | 50 | "nounPhrase(adj = <<adj_>>) np:\n"; |
| | 51 | np_.debugPrint(level+1); |
| | 52 | } |
| | 53 | ; |