Prolog assignment

Hey everyone, can you help me to solve these two exercises thanks in advance :slight_smile:

Task 1: Some list exercises

Make use of the DCG listed below which is using extra arguments to construct the parse tree.

s(s(NpT,VpT)) β†’ np(NpT), vp(VpT).
np(np(DetT,NT)) β†’ det(DetT), n(NT).
np(np(PnT)) β†’ pn(PnT).
vp(vp(ViT)) β†’ vi(ViT).
vp(vp(VtT,NpT)) β†’ vt(VtT), np(NpT).

%% Lexicon

det(det(a)) β†’ [a].
det(det(the)) β†’ [the].
n(n(bride)) β†’ [bride].
n(n(nurse)) β†’ [nurse].
n(n(yakuza)) β†’ [yakuza].
n(n(whiskey)) β†’ [whiskey].
pn(pn(bill)) β†’ [bill].
pn(pn(gogo)) β†’ [gogo].
vi(vi(whistles)) β†’ [whistles].
vi(vi(fights)) β†’ [fights].
vt(vt(drinks)) β†’ [drinks].
vt(vt(kills)) β†’ [kills].

Load it and type listing. You will see that Prolog translated the user friendly β†’ notation to its
internal DCG format.

To find out whether a list of words is a sentence and to receive the corresponding parse tree P,
you have to ask s(P,WordList,). Try some queries and note their result. Maybe do a trace.

Task 2: Write a parser for your own DCG

If you haven’t done so already, do task 2 of day 3.

Then turn this DCG into a parser by adding an extra argument for constructing the parse tree, as we
have done for the English grammar in the lecture and as you can see in assignment 1.

a. Ask some queries (parse some sentences) and note their results.

b. Generate the first 5 sentences of your grammar and note the result.

You want other people to do your work for you? Got it. Not how the world works, get used to that.