Write a PROLOG program that will take grammar rules in the following format: NT (NT | T)* Where NT is any nonterminal, T is any terminal and Kleene star (*) signifies any number of repetitions, and generate the corresponding top-down parser, that is: sentence  noun-phrase, verb-phrase determiner  [the] will generate the following: sentence (I, O) :- noun-phrase(I,R), verb-phrase (R,O). determiner ([the|X], X) :- !.

24.Write a PROLOG program that will take grammar rules.

% PROLOG program that will take grammar rules.

%  below sets of  function is not predefined you can use any name as function

det([the|X],X):-!.
noun([sohan|X],X).
noun([frog|X],X).
verb([loves|X],X):-!.

sentence(P1,P3):- np(P1,P2),vp(P2,P3).
np(P1,P2):- noun(P1,P2).
np(P1,P3):- det(P1,P2),noun(P2,P3).
vp(P1,P3):- verb(P1,P2), np(P2,P3).

No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...