next up previous
Next: How do DCGs Up: No Title Previous: Useful Tip 6

Definite Clause Grammars

DCGs are a special notation provided in most Prolog systems which provide you with a convenient way of defining grammar rules. The general form of each DCG clause is as follows:

Head --> Body
meaning ``A possible form for Head is Body''. Head and Body are Prolog terms and `-->' is an infix operator.

The most common use of DCGs is to parse (or generate) some list of symbols according to valid ``rules of grammar'' defined by the DCG clauses. DCGs can be used for purposes other than parsing but for the purposes of this explanation we will stick with the standard parsing application.

Agree to call the symbols (usually words) in the parsed sentence "terminal symbols". Also agree to call symbols which represent higher level language constructs "non-terminal symbols".





Dave Stuart Robertson
Tue Jul 7 10:44:26 BST 1998