This version has a fairly limited vocabulary and sentence structure, but more words can be added (trivial) and more grammar rules can be added as well.
In particular, having a rule for subordinate clauses wouldit should be cool (e.g. 'The food which I ate rest_of_sentence'). This would give much more interesting sentencespretty easy to extend.
% VocabularyDefine the vocabulary verb(V) :- V = 'eats' | V = 'fights' | V = 'finds'. subj_pronoun(P) :- P = 'he' | P = 'she' | P = 'it'. obj_pronoun(P) :- P = 'him' | P = 'her' | P = 'it'. name(N) :- N = 'alice' | N = 'bob'. noun(N) :- N = 'cat' | N = 'door' | N = 'pen'. article(H) :- H = 'the' | H = 'a'. % Grammar obj_nounsubject_phrase_short(NH) :- nounsubj_pronoun(NH) | obj_pronounname(NH). subject_phrase% Subordinate clause. Don't use verb_phrase here to avoid recursive clauses. sub_clause([H][Which, Verb|T], Rest) :- subj_pronounWhich = 'which', verb(HVerb), | name object_noun_phrase_short(T, Rest). subject_phrase([H|T], Rest) :- subject_phrase_short(H), Rest = T. noun_phraseobject_noun_phrase_short([A, N]N | T], Rest) :- article(A), noun(N), Rest = T | obj_pronoun(A), Rest = [N|T]. object_phrase([H|T]L, Rest) :- noun_phraseobject_noun_phrase_short([H|T]L, Rest) | object_noun_phrase_short(L, Rest1), sub_clause(Rest1, Rest). verb_phrase([H|T], Rest) :- verb(H), object_phrase(T, Rest). sentence([H|T]S) :- subject_phrase([H]S, Rest), verb_phrase(TRest, []). L = [he, eats, the, cat] ; L = [she, finds, a, door] ; L = [alice, fights, the, door] ; L = [he, fights, the, cat, which, eats, the, pen] ; L = [alice, eats, him, which, finds, the, cat] ; (EDIT: Allow object subordinate clauses).