% Grammar 5.8: A depth-bounded DCG in BH-GRN.
% Requires Program C.1 to be loaded first.

:-op(1100, xfx, --->).
:-op(1100, xfx, ===>).

s(Depth) ---> 
    {Depth > 0, NewDepth is Depth - 1},
    [np(NewDepth), vp(NewDepth)].

vp(Depth) ---> 
    {Depth > 0, NewDepth is Depth - 1},
    [v(NewDepth)].

vp(Depth) ---> 
    {Depth > 0, NewDepth is Depth - 1},
    [v(NewDepth), np(NewDepth)].

vp(Depth) ---> 
   {Depth > 0, NewDepth is Depth - 1},
   [vp(NewDepth), pp(NewDepth)].

pp(Depth) ---> 
   {Depth > 0, NewDepth is Depth - 1},
   [p(NewDepth), np(NewDepth)].

np(Depth) ---> 
   {Depth > 0, NewDepth is Depth - 1},
   [np(NewDepth), pp(NewDepth)].

np(_) ===> [toby].
np(_) ===> [scotch].
np(_) ===> [drinks].
np(_) ===> [ice].

v(_) ===> [drinks].

p(_) ===> [on].
