[Previous] [Up] [Next]
Go backward to Difference Lists
Go up to Difference Lists and Definite Clause Grammars
Go forward to Prolog Samples

Definite Clause Grammars

The implementation of phrase structure rules described in the previous section is so common that there is a Prolog shorthand for writing the rules. Instead of

you write
s --> np, vp.
np --> noun.
vp --> verb, np.
The latter notation uses the OPERATOR --> (you can read more about operators in Operators in More About Prolog) instead of the usual :-. A grammar in this format is called a DEFINITE CLAUSE GRAMMAR. Many versions of Prolog, including SICStus, has a built-in DCG-interpreter which is a program that convert rules in the DCG-format into Prolog rules. In other Prologs, you have to load a file which does the interpreting prior to loading the file with the DCG-rules.

When you write a phrase structure grammar in Prolog, you will normally use the --> operator in your grammar rules. When you consult the file, the Prolog interpreter recognises the --> which causes it to first use the DCG-interpreter to rewrites the rule into Prolog rules with difference lists. The Prolog version is then loaded into the interpreter. You can see this is what happens by typing listing after you have loaded a file with a DCG.

DCG rules which rewrite nodes into terminals use the same operator:

noun --> [john]. 
noun --> [mary]. 
verb --> [loves]. 
verb --> [hates]. 
The DCG-interpreter reconstructs them into Prolog facts of the following format:
det(SO,S):- 'C'(S0,every,S).
The 'C' stands for "connects" (the single quotes are needed to allow a string of letters which start in an uppercase letter to be treated as a constant). The translation of dictionary rules is thus not identical to the format we used above
but the effect is the same. The 'C' and the long-winded translation are historical leftovers.


[Previous] [Up] [Next]