/* DCG in Picat. From Nilsson & Matuszynski: "Logic, Programming and Prolog" Page 194f (Chapter 10: Logic and Grammar) This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import v3_utils. main => go. /* Picat> cl(dcg_sentence1),sentence(X,Y,[]) X = s(john,runs) Y = [john,runs] ?; no Trace before first solution: Picat> trace Picat> cl(dcg_sentence1),sentence(X,Y,[]) Call: (1) sentence(_13c20,_13c28,[]) ?r Call: (2) s(_14190,_14198) = _13c20 Exit: (2) s(_14190,_14198) = s(_14190,_14198) Call: (3) np(_14190,_14ae8,_13c28,_14af8) Call: (4) var(_14190) Exit: (4) var(_14190) Call: (5) john = _14190 Exit: (5) john = john Call: (6) singular(3) = _14ae8 Exit: (6) singular(3) = singular(3) Call: (7) _13c28 = [john|_14af8] Exit: (7) [john|_14af8] = [john|_14af8] ? Exit: (3) np(john,singular(3),[john|_14af8],_14af8) Call: (8) vp(_14198,singular(3),_14af8,[]) Call: (9) runs = _14198 Exit: (9) runs = runs Call: (10) singular(3) = singular(3) Exit: (10) singular(3) = singular(3) Call: (11) _14af8 = [runs] Exit: (11) [runs] = [runs] ? Exit: (8) vp(runs,singular(3),[runs],[]) ? Exit: (1) sentence(s(john,runs),[john,runs],[]) X = s(john,runs) Y = [john,runs] ?; */ go ?=> sentence(X,Y,[]), println(X=Y), fail, nl. go => true. % % Variant: singular/1 -> singular/0, plural/1 -> plural/0 % % Picat> sentence2(X,Y,[]) % X = s(john,runs) % Y = [john,runs] ?; % no % go2 ?=> sentence2(X,Y,[]), println(X=Y), fail, nl. go2 => true. % % Original % sentence(s(X,Y)) --> np(X,N), vp(Y,N). np(john,singular(3)) --> [john]. np(they,plural(3)) --> [they]. np(run,plural(_X)) --> [run]. vp(runs,singular(3)) --> [runs]. % % skipping the numeric parameter to singular/1 and plural/1 % sentence2(s(X,Y)) --> np2(X,N), vp2(Y,N). np2(john,singular) --> [john]. np2(they,plural) --> [they]. np2(run,plural) --> [run]. vp2(runs,singular) --> [runs].