% A depth-bounded DCG}
% gramdbdcg.pl

:- op(1200, xfx, --->).
:- op(1200, 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(Depth) ===> [toby].
 np(Depth) ===> [scotch].
 np(Depth) ===> [drinks].
 np(Depth) ===> [ice].
 v(Depth) ===>  [drinks].
 p(Depth) ===>  [on].