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 writes(Sentence,Hole):- np(Sentence,Rest), vp(Rest,Hole). np(NP,Hole):- noun(NP,Hole). vp(VP,Hole):- verb(VP,Rest), np(Rest,Hole).
The latter notation uses the OPERATORs --> np, vp. np --> noun. vp --> verb, np.
-->(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:
The DCG-interpreter reconstructs them into Prolog facts of the following format:noun --> [john]. noun --> [mary]. verb --> [loves]. verb --> [hates].
Thedet(SO,S):- 'C'(S0,every,S). 'C'([Head|Hole],Head,Hole).
'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.noun([john|Rest],Rest). noun([mary|Rest],Rest). verb([loves|Rest],Rest).