% Depth-bounded top-down Prolog parser}
% progdbtdparser.pl
:- op(1200, xfx, --->).
:- op(1200, xfx, ===>).
td_parse(Cat, Depth, [Word|RestofString],RestofString) :-
   (Cat===> [Word]).
td_parse(Mother, Depth, S0,S) :-
    Depth > 0, NewDepth is Depth - 1,
    (Mother ---> Daughters),
   td_parse_dtrs(Daughters, NewDepth, S0,S).
td_parse_dtrs([], _, S, S).
td_parse_dtrs([Cat | Cats], Depth, S0,S) :-
   td_parse(Cat, Depth, S0,S1),
   td_parse_dtrs(Cats, Depth, S1,S).