:- begin(gram).

varre -+-> np(Sn,On), 
           { % write(Sn),
	     % nl,
             writelist(On)},
           !,varre.
varre -+-> [eof],! .
varre -+-> [_],!,varre.

np(npp(S1,ppos(Sa),Sn,Sad1,Sad),[A,B,C,D,E|Spp]) -+-> 
   ?[art(_,_)-S1+A],
   ?[ppos(_,_,_)-Sa+B],
   ?[adj(_,_)-Sad1+C],
   [nc(_,_)-Sn+D],
   ?[adj(_,_)-Sad+E],
   opp(Spp).


np(npp(S1,ppos(Sa),Sn,Sad1,Sad),[A,B,C,D,E]) -+-> 
   ?[cp-S1+A],?[ppos(_,_,_)-Sa+B],?[adj(_,_)-Sad1+C],[nc(_,_)-Sn+D],?[adj(_,_)-Sad+E].

np(n(Sn),A)           -+-> [nc(_,_)-Sn+A].

opp([de|L]) -+-> [de],np(_,L).
opp([H|L]) -+-> [cp-S1+H],np(_,L).
opp([]) -+->!, [].

:- end(gram).

writelist([]):- nl,!.
writelist([H|T]):- (var(H) -> true; write(H),write(' ')),writelist(T),!.
writelist(H):- write(H),!.

test('o meu gato e a minha avó dormem. a vaca fugiu').
test('minha gata e a casa grande grande fria fazem sombra').
testfile(texto).
make(A) :- test(A),set_string(A),varre.
make(A) :- testfile(A),set_file(A),varre.
