Reputation: 1
PROLOG: “Syntax error: Operator expected” ERROR: c:/users/zulfekarali/Desktop/KBS/kbs.pl:2:3: Syntax error: Operator expected % c:/Users/ZulfekarAli/Desktop/KBS/kbs.pl compiled 0.00 sec, 27 clauses -------- domains disease,indication = symbol Patient,name = string predicates hypothesis(string,disease) symptom(name,indication) response(char) go clauses go :- write("What is the patient's name? "), readln(Patient), hypothesis(Patient,Disease), write(Patient,"probably has ",Disease,"."),nl. go :- write("Sorry, I don't seem to be able to"),nl, write("diagnose the disease."),nl. symptom(Patient,fever) :- write("Does ",Patient," have a fever (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,rash) :- write("Does ",Patient," have a rash (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,headache) :- write("Does ",Patient," have a headache (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,runny_nose) :- write("Does ",Patient," have a runny_nose (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,conjunctivitis) :- write("Does ",Patient," have a conjunctivitis (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,cough) :- write("Does ",Patient," have a cough (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,body_ache) :- write("Does ",Patient," have a body_ache (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,chills) :- write("Does ",Patient," have a chills (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,sore_throat) :- write("Does ",Patient," have a sore_throat (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,sneezing) :- write("Does ",Patient," have a sneezing (y/n) ?"), response(Reply), Reply='y'. symptom(Patient,swollen_glands) :- write("Does ",Patient," have a swollen_glands (y/n) ?"), response(Reply), Reply='y'. hypothesis(Patient,measles) :- symptom(Patient,fever), symptom(Patient,cough), symptom(Patient,conjunctivitis), symptom(Patient,runny_nose), symptom(Patient,rash). hypothesis(Patient,german_measles) :- symptom(Patient,fever), symptom(Patient,headache), symptom(Patient,runny_nose), symptom(Patient,rash). hypothesis(Patient,flu) :- symptom(Patient,fever), symptom(Patient,headache), symptom(Patient,body_ache), symptom(Patient,conjunctivitis), symptom(Patient,chills), symptom(Patient,sore_throat), symptom(Patient,runny_nose), symptom(Patient,cough). hypothesis(Patient,common_cold) :- symptom(Patient,headache), symptom(Patient,sneezing), symptom(Patient,sore_throat), symptom(Patient,runny_nose), symptom(Patient,chills). hypothesis(Patient,mumps) :- symptom(Patient,fever), symptom(Patient,swollen_glands). hypothesis(Patient,chicken_pox) :- symptom(Patient,fever), symptom(Patient,chills), symptom(Patient,body_ache), symptom(Patient,rash). hypothesis(Patient,measles) :- symptom(Patient,cough), symptom(Patient,sneezing), symptom(Patient,runny_nose). response(Reply) :- readchar(Reply), write(Reply),nl.
Upvotes: 0
Views: 5957
Reputation: 3407
The code you provide is invalid SWI-Prolog code because of several reasons.
The already observed occurrence of non-commented free text before the first occurrence of go:-
.
The predicates write/[3,4]
do not exist in SWI-Prolog.
Predicate readln/1
exists in library readln
. Even though this module is auto-loaded, it is better to make the dependency explicit using declaration :- use_module(library(readln)).
at the top of the file.
More importantly, readln/1
returns lists, but hypothesis/2
and symptom/2
seem to anticipate non-list input.
There is a mismatch between the elements in readln/1
which are atoms and the other arguments of write/[3,4]
that are strings.
Upvotes: 1
Reputation: 831
domains
disease,indication = symbol
Patient,name = string
predicates
hypothesis(string,disease)
symptom(name,indication)
response(char)
go
clauses
I think this piece of code should be commented with %
symbol in order to fix the syntax error.
And here, as another issue, you might want to cut (!
) at the final of the predicate, otherwise Prolog because of backtracking will try the second go
when it succeeds this first one.
go :-
write("What is the patient's name? "),
readln(Patient),
hypothesis(Patient,Disease),
write(Patient,"probably has ",Disease,"."),nl,!.
Upvotes: 1