/* sentence/2 sentence(+S,-D) The predicate sentence returns a derivation if the list of tokens has a valid derivation according to the grammar rules. This definite clause grammar is written without the --> macro. Warren Sack May 2017 */ append([],List,List). append([First|Rest],List2,[First|List3]) :- append(Rest,List2,List3). sentence(Sentence,sentence(NP,VP)) :- append(NounPhrase,VerbPhrase,Sentence), noun_phrase(NounPhrase,NP), verb_phrase(VerbPhrase,VP). noun_phrase(NounPhrase,noun_phrase(A,N)) :- append(Article,Noun,NounPhrase), article(Article,A), noun(Noun,N). verb_phrase(VerbPhrase,verb_phrase(V,NP)) :- append(Verb,NounPhrase,VerbPhrase), verb(Verb,V), noun_phrase(NounPhrase,NP). article([a],article(a)). article([the],article(the)). noun([man],noun(man)). noun([ball],noun(ball)). verb([hit],verb(hit)). verb([took],verb(took)).