如何修复语法错误:需要运算符

问题描述 投票:0回答:1

运行代码时出现两个错误

geneholtproj6.swipl:165:2: Syntax error: Operator expected
geneholtproj6.swipl:291:3: Syntax error: Operator expected
This is the first error.  Line 165.2 would refer to the first !.
/*does nothing if you aren't there*/
key:-
at(you,key),
write('you have found the key'),
retract(at(you,maze(2)),
assert(at(you,key)),
!.

/*If you are at the same place as the magic pants*/
magic_pants:-
at(magic_pants,Loc),
at(you,Loc),
write('Magic pants?! I wonder what these do!'),
!.




This is the second error.  Line 291:3 would refer to main.
go :-
retractall(at(_,_)), /* clean up from previous runs */
retract(at(you, maze(2)),
move(at(you, treasure),
move(at(you, mountaintop),
assert(at(you,valley)),
assert(at(ogre,maze(3))),
assert(at(key,maze(2))),
assert(at(gate_pants,meadow)),
assert(at(treasure,mountaintop)),
write('This is an adventure game.\n'),
write('Legal moves are left, right, forward, or backward.\n'),
write('To pick up items type take(x).\n'),
write('To drop items drop(x).\n'),
write('End each move with a period.\n\n'),
report,
main.

我已经多次检查了代码,但我认为我需要重新审视这一点。如有任何帮助,我们将不胜感激。

prolog
1个回答
0
投票

您的代码中存在一些不平衡的括号:

在您的

key
程序中:

retract(at(you,maze(2)),  % <===  retract(at(you,maze(2))),

在您的

go
程序中:

retract(at(you, maze(2)),  % <===  retract(at(you, maze(2)))
move(at(you, treasure),  % <===  move(at(you, treasure))
move(at(you, mountaintop),  % <===  move(at(you, mountaintop))
© www.soinside.com 2019 - 2024. All rights reserved.