programa --> regra; fato.
DCG: sent --> frase_nominal, frase_verbal, complemento.
Prolog: sent(S0,S) :- frase_nominal(S0,S1),
frase_verbal(S1,S2),
complemento(S2,S).
DCG: artigo --> [a]. Prolog: artigo([a|R],R).
DCG: constante(Dic,I) --> [segunda],
{lookup(segunda,Dic,I)}.
Prolog: constante(Dic,I,[segunda|R],R) :-
lookup(segunda,Dic,I).
sentence(sentence(NP,VP)) -->
noun_phrase(NP),
verb_phrase(VP).
noun_phrase(np(D,N,C)) -->
determiner(D),
noun(N),
rel_clause(C).
noun_phrase(np(PN)) -->
proper_noun(PN).
verb_phrase(vp(TV,NP)) -->
trans_verb(TV),
noun_phrase(NP).
verb_phrase(vp(IT)) -->
intrans_verb(IT).
rel_clause(rc(that,VP)) -->
[that],
verb_phrase(VP).
rel_clause(rc([])) --> [].
determiner(det(every)) --> [every]. determiner(det(a)) --> [a]. noun(noun(man)) --> [man]. noun(noun(woman)) --> [woman]. proper_noun(pn(john)) --> [john]. trans_verb(tv(loves)) --> [loves]. intrans_verb(iv(lives)) --> [lives].
:-op(500,xfy,&).
:-op(600,xfy,'->').
sentence(P) -->
noun_phrase(X,P1,P),
verb_phrase(X,P1).
noun_phrase(X,P1,P) -->
determiner(X,P2,P1,P),
noun(X,P3),
rel_clause(X,P3,P2).
noun_phrase(X,P,P) -->
proper_noun(X).
verb_phrase(X,P) -->
trans_verb(X,Y,P1),
noun_phrase(Y,P1,P).
verb_phrase(X,P) -->
intrans_verb(X,P).
rel_clause(X,P1,(P1&P2)) -->
[that],
verb_phrase(X,P2).
rel_clause(_,P,P) --> [].
determiner(X,P1,P2,all(X,(P1->P2))) --> [every]. determiner(X,P1,P2,exists(X,(P1&P2))) --> [a]. noun(X,man(X)) --> [man]. noun(X,woman(X)) --> [woman]. proper_noun(john) --> [john]. trans_verb(X,Y,loves(X,Y)) --> [loves]. intrans_verb(X,lives(X)) --> [lives].
+---+ +---+
| C | | A |
+---+ +---+
| A | ===> | B |
+---+ ?? +---+
| B | | C |
+---+ +---+
///// /////
% mv Top1 to St2 em Sit2 s(Stacks,[St1,[Top1|St2]|Otherstacks]) :- % [Top1|St1] e' uma pilha em Sit1 del([Top1|St1],Stacks,Stacks1), % St2 e' uma pilha em Sit1 del(St2,Stacks1,Otherstacks).
goal(Estado) :- pertence([a,b,c],Estado).
solve(Inicio,Fim).
solve(N,[N]) :- goal(N).
solve(N,[N|Sol1]) :-
s(N,N1), % implem. disto depende do prob.
solve(N1,Sol1).
solve(N,[N],_) :- goal(N).
solve(N,[N|Sol1],ProfMax) :-
ProfMax > 0,
s(N,N1),
NewMax is ProfMax - 1,
solve(N1,Sol1,NewMax).
bfs(Inicio,Fim) :- solve([[Inicio]],Fim).
solve([[N|Path]|_],[N|Path]) :- goal(N).
solve([Path|Paths],Solucao) :-
extend(Path,NewPaths),
conc(Paths,NewPaths,Paths1),
solve(Paths1,Solucao).
extend([Node|Path],NewPaths) :-
bagof([NewNode,Node|Path],
(s(Node,NewNode), \+ pertence(NewNode,[Node|Path])),
NewPaths), !.
extend(Path,_). % no nao tem sucessor.