2013-05-14 60 views
1

一些代碼,我寫了一個明確的條款語法 我跟着書「學的Prolog現在」非常密切序言,定子句語法

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))}. 

下面是一個查詢我問上面的代碼

3? - s([the,student,does,his,assignment],[])。 出錯:本地棧

我已經嘗試過重新定位的詞彙,但是當我編譯它

很抱歉,如果我不寫的問題,沒有工作 至於語法錯誤,沒有什麼明顯回升好吧,但我不知道還有什麼要說的,如果你需要關於代碼的更多信息,請留下評論,我會盡我所能地嘗試回答。

回答

1

問題是s // 0是遞歸的。你應該修改第一條規則。例如

s --> p, conj, s. 
p --> np(X),vp(X). 
...