/* * test of part-of-speech lists in grammar definitions */ #include #include #include dictionary gDict; dictionary property nounM, nounF, nounN; bookM: object desc = 'book' nounM = 'book' ; boxF: object desc = 'box' nounF = 'box' ; bagN: object desc = 'bag' nounN = 'bag' ; grammar nounPhrase: ->noun_ : object desc = "nounPhrase: noun = <>" ; grammar nounPhrase: nounN->noun_ : object desc = "nounPhrase: noun = <>" ; main(args) { "Enter an empty line to quit.\b"; /* keep going until done */ for (;;) { local str; local match; /* read a line */ "Type a noun: "; str = inputLine(); /* if it's empty, quit */ if (str == '' || str == nil) break; /* parse it */ match = nounPhrase.parseTokens(Tokenizer.tokenize(str), gDict); /* show any matches */ foreach (local cur in match) { cur.desc; "\n"; } } }