All Manuals > KnowledgeWorks and Prolog User Guide > A Common Prolog > A.9 Defining Definite Clause Grammars > A.9.1 Examples

NextPrevUpTopContentsIndex

A.9.1.1 Example 1: A simple definition.

This example shows the Common Prolog translation of the grammar shown at the top of http://cs.union.edu/~striegnk/learn-prolog-now/html/node59.html

(defgrammar gram-det
  (gram-det the)
  (gram-det a))
 
(defgrammar gram-n
  (gram-n woman)
  (gram-n man))
 
(defgrammar gram-v
  (gram-v shoots))
 
(defgrammar gram-np
  (gram-np (gram-det) (gram-n)))
 
(defgrammar gram-vp
  (gram-vp (gram-v) (gram-np))
  (gram-vp (gram-v)))
 
(defgrammar gram-s
  (gram-s (gram-np) (gram-vp)))

Note the use of symbols for terminals and lists for non-terminals. They all use the first form of the <lhs> and have no extra terms on the <rhs>, so all of the relations are binary.

The following will both succeed and bind ?x to the list (foo bar):

(clog:any '?x '(gram-s (a woman shoots foo bar) ?x))
(clog:any '?x '(gram-s (a woman shoots the man foo bar) ?x))

 


KnowledgeWorks and Prolog User Guide (Unix version) - 26 Feb 2015

NextPrevUpTopContentsIndex