A Definite Clause Grammar is given by a set of production rules. Where the head contains only a single non terminal. Here is a simple example.
In fact most prolog environments incorporate a mechanism that causes DCG's to be transformed into prolog code by adjoining two extra variables. (If you want to see how prolog does the translation click HERE .) That is why I have written the above grammar in prolog style.
The above DCG would translate to the following prolog code.
Adding to the usefulness of DCGs is the ability to have additional arguments on the grammar elements. So that we can do number agreement with the above grammar as follows
You can incorporate prolog code that is to be passed though unchanged in the course of the translation process. Simply enclose it in braces ({}). For an interesting example of this that recognises numbers click HERE
To return to the AI home page click AIHOME.
Jonathan Hodgson
Last Changed 23/11/94