next up previous contents
Next: To Use the Up: Parsing in Prolog Previous: A Second Approach

Prolog Grammar Rules

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.



sentence   		  --> 		  noun_phrase
verb_phrase.

noun_phrase --> determiner noun.

verb_phrase --> verb noun_phrase.

determiner --> [a].

determiner --> [the].

noun --> [man].

noun --> [cake].

verb --> [ate].

It is very easy to extend if we want to include adjectives.


noun_phrase 		 --> 		  determiner
adjectives
noun.

adjectives --> adjective.

adjectives --> adjective adjectives.

adjective --> [young].

This formulation is sometimes known as a Definite Clause Grammar (DCG).

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:



sentence 		    --> 		  noun_phrase
verb_phrase.

and Prolog turns this into:


sentence(S
S0):-

noun_phrase(S S1)

verb_phrase(S1 S0). [-5pt]

and


adjective 		   --> 		  [young].

[-5pt]

into


adjective(A
A0):-

'C'(A young A0). [-5pt]

where 'C'/3 is a built in Prolog Predicate which is defined as if:


'C'([HT]
H
T).



Paul Brna
Mon May 24 20:14:48 BST 1999