3.2.2 Using DCGs

A DCG for the fragment of English we shall use in our initial semantic construction experiments (this DCG can be found in the file usingDCG.pl).

usingDCG.pl: View Download

Here is a DCG for the fragment of English we shall use in our initial semantic construction experiments (this DCG can be found in the file usingDCG.pl).

A Context-free Grammar using DCG

s --> np, vp.               

np --> pn.                 
np --> det, noun.         

pn --> [john].             
pn --> [mary].                

det --> [a].
det --> [every]. 

noun --> [woman].
noun --> [siamese,cat].  

vp --> iv.
vp --> tv, np.

iv --> [walks].

tv --> [loves].

This grammar tells us how to build certain kinds of sentences (s) out of noun phrases (np), verb phrases (vp), proper names (pn), determiners (det), nouns (noun), intransitive verbs (iv), and transitive verbs (tv). In addtion it gives us a tiny lexicon to play with.

An analysis of why this grammar accepts the simple sentence ``John walks'' would be this: ``John'' is declared a proper name, with proper names being noun phrases according to this grammar; ``walks'' is an intransitive verb, and hence a verb phrase; and our grammar licenses sentences that consist of a noun phrase followed by a verb phrase.

Since DCGs are part and parcel of Prolog, we can actually compute with them. For example, by posing the query s([mary,likes,a,siamese,cat],[]) we can test whether ``Mary likes a siamese cat'' is accepted by the grammar, or we can use s(X,[]),write(X),nl,fail to generate all grammatical sentences.

?- Question!

How many sentences are accepted by this grammar? How many noun phrases, how many verb phrases does it allow? Check your answers by generating the relevant items.


Aljoscha Burchardt, Stephan Walter, Alexander Koller, Michael Kohlhase, Patrick Blackburn and Johan Bos
Version 1.2.5 (20030212)