Prolog as a convenience will do most of the tedious work for you. What follows is the way you can take advantage of Prolog.
This is how we can define the simple grammar which is accepted `as is' by Prolog.
sentenceIt is very easy to extend if we want to include adjectives.-->noun_phrase verb_phrase.noun_phrase
-->determiner noun.verb_phrase
-->verb noun_phrase.determiner
-->[a].determiner
-->[the].noun
-->[man].noun
-->[cake].verb
-->[ate].
noun_phraseThis formulation is sometimes known as a Definite Clause Grammar (DCG).-->determiner adjectives noun.adjectives
-->adjective.adjectives
-->adjective adjectives.adjective
-->[young].
We might later think about the ordering of these rules and whether they really capture the way we use adjectives in general conversation but not now.
Essentially the Prolog Grammar Rule formulation is syntactic sugaring. This means that Prolog enables you to write in:
sentenceand Prolog turns this into:-->noun_phrase verb_phrase.
sentence(S S0):-andnoun_phrase(S S1)
verb_phrase(S1 S0). [-5pt]
adjectiveinto-->[young]. [-5pt]
adjective(A A0):-where 'C'/3 is a built in Prolog Predicate which is defined as if:'C'(A young A0). [-5pt]
'C'([HT] H T).