/* Variant of the depth-first, left-to-right parser
that also builds trees in the form of lists of
lists. It requires the grammar file to be loaded
first.
Here is how the parser is called:
| ?- parse(s, T, [the,dog,chased,the,cat], []).
T = [s,[np,[det,the],[n,dog]],[vp,[v,chased],[np,[det,the],[n,cat]]]] ?
yes
*/
parse(Cat, [Cat,Firstword], [Firstword|Restwords], Restwords):-
Cat ==> Firstword.
parse(Cat, [Cat|Tree], String, Rest ):-
(Cat ==> Daughters),
parserest(Daughters, Tree, String, Rest).
parserest((Cat, Cats), [Tree, Resttree], String, Rest):-
parse(Cat, Tree, String, Next),
parserest(Cats, Resttree, Next, Rest).
parserest(Cat, Tree, String, Rest):-
parse(Cat, Tree, String, Rest).