質問

Some code I wrote for a definite clause grammar I followed the book "Learn Prolog Now" very closely

lex(the,det(single)).
lex(the,det(plural)).
lex(a,det(single)).
lex(some,det(plural)).
lex(at,det(single)).

lex(student,n(single)).
lex(students,n(plural)).
lex(assignment,n(single)).
lex(assignments,n(plural)).
lex(teacher,n(single)).
lex(teachers,n(plural)).
lex(lecture,n(single)).
lex(lecture,n(plural)).
lex(school,n(single)).
lex(home,n(single)).

lex(does,v(single)).
lex(do,v(plural)).
lex(corrects,v(single)).
lex(correct,v(plural)).
lex(writes,v(single)).
lex(write,v(plural)).
lex(gives,v(single)).
lex(give,v(plural)).

lex(his,pro(single)).
lex(her,pro(single)).
lex(their,pro(plural)).

lex(and,conj).
lex(while,conj).

s--> s, conj, s.
s--> np(X),vp(X).
np(X)--> det(X),n(X);pro(X), n(X).
vp(X)--> v(X), np(X).
vp(X)--> v(X).
det(X)--> [A],{lex(A,det(X))}.
pro(X)--> [A],{lex(A,pro(X))}.
v(X)--> [A],{lex(A,v(X))}.
n(X)--> [A],{lex(A,n(X))}.

Below is a query I asked for the above code

3 ?- s([the,student,does,his,assignment],[]). ERROR: Out of local stack

I already tried repositioning the lexicon but that didn't work As for syntax errors, nothing was picked up when I compiled it

Sorry if I didn't write the question well but I don't know what else to say, if you need any more information about the code leave a comment and I'll try answer as best I can.

役に立ちましたか?

解決

the problem is that s//0 is left recursive. You should amend the first rule. For instance

s --> p, conj, s.
p --> np(X),vp(X).
...
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top