Making a randomizer code figure out grammar

I want to make a randomizer code that understands how to reply to sentences. Example: If a sprite asks a question, reply with an answer.


I also want the randomizer code to understand grammar. Example: Instead of the original code making sentences like “I’m car your smell?”, it will make a sentence like “Why does your car smell?” (@d016 brought this to my attention. The original sentences were like that because I wanted them to be nonsensical, but I thought it was a good idea.)

Only exception: Answers and sentences do not have to make sense, I just want them to at least be grammatically correct.

If you generate each type of response (question, answer, statement) with its own formula, you could store metadata alongside the response to let the other sprite know what to respond with. For example, you could store the response like this:
{generate random reply::reporter}::hat script variables ((what you want the thing to say)) ((what you want the thing to be treated like))@delInput@addInput set [what you want the thing to be treated like V] to (item (random v) of (list [question] [statement]@delInput@addInput)) ... //add whatever you want here, just make it follow what you want it to be treated like report (list (what you want the thing to say)(what you want the thing to be treated like)@delInput@addInput
and then do this:
when I receive [message V] ((data))@delInput say (item (1 v) of (data)) for (3) secs if <(item (2 v) of (data))=[question]> then{ broadcast [message V] to [Sprite2 V]with data (generate answer::) @delInput } else{ broadcast [message V] to [Sprite2 V]with data (generate random reply::) @delInput }