General
Lab Material
Lab 1
Lab 2
Lab 3
Lab 4
Lab 5
Lab 6

Simple extensions to the DCG

Load this DCG type listing. You will see that Prolog translated the user friendly --> notation to its internal DCG format.

To find out whether a list words L is a sentence, you have to ask the query s(L,[]). But you can also ask whether it is a noun phrase by asking np(L,[]), or whether it starts with a noun phrase by asking np(L,Rest).

Play with the DCG a bit: ask some queries and maybe do a trace.

Now make some simple extensions to this DCG. For example:

  • Add further words to the lexicon.
  • Extend the grammar so that it can also handle ditransitive verbs of the form:
    the barkeeper gives her a sword
    Solution
  • Extend the grammar so that it can also handle nouns which are modified by a prepositional phrase:
    the nurse with the glasses whistles
    Solution

Back to lab 1.