np.168 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. "Create the oblists for the vocabulary, if necessary"
  2. <SETG WORDS <OR <GET WORDS OBLIST> <MOBLIST WORDS 23>>>
  3. <SETG OBJECT-OBL <OR <GET OBJECTS OBLIST> <MOBLIST OBJECTS 23>>>
  4. <SETG ACTIONS <MOBLIST ACTIONS 17>>
  5. <SETG DIRECTIONS <MOBLIST DIRECTIONS>>
  6. "Create the structure in which prepositional phrases are stored at parse
  7. time. Don't bother when COMPILEing or GLUEing."
  8. <SETG LAST-IT <FIND-OBJ "#####">>
  9. <GDECL (LAST-IT) OBJECT>
  10. <COND (<OR <LOOKUP "COMPILE" <ROOT>> <GASSIGNED? GROUP-GLUE>>)
  11. (T
  12. <SETG PREPVEC
  13. [<CHTYPE [<FIND-PREP "WITH"> <FIND-OBJ "#####">] PHRASE>
  14. <CHTYPE [<FIND-PREP "WITH"> <FIND-OBJ "#####">] PHRASE>]>
  15. <SETG PREP2VEC
  16. [<CHTYPE [<FIND-PREP "WITH"> <FIND-OBJ "#####">] PHRASE>
  17. <CHTYPE [<FIND-PREP "WITH"> <FIND-OBJ "#####">] PHRASE>]>)>
  18. "Randomness"
  19. <SETG NEFALS #FALSE (1)>
  20. ;"funny falses for SEARCH-LIST and FWIM"
  21. <SETG NEFALS2 #FALSE (2)>
  22. <SETG SSV <IVECTOR 10 <>>>
  23. ;"Uvector for BUNCHing"
  24. <SETG BUNUVEC <REST <IUVECTOR 8 <FIND-OBJ "#####">> 8>>
  25. ;"BUNCH object"
  26. <TRO <SETG BUNCH-OBJ <FIND-OBJ "BUNCH">> ,OVISON>
  27. ;"VERBs which take BUNCHes"
  28. <SETG BUNCHERS ()>
  29. ;"Current BUNCH"
  30. <SETG BUNCH ,BUNUVEC>
  31. <GDECL (BUNUVEC BUNCH) <UVECTOR [REST OBJECT]> (BUNCHERS) <LIST [REST VERB]>>
  32. \
  33. "EPARSE -- top level entry to parser. calls SPARSE to set up the
  34. parse-vector, then, calls SYN-MATCH to see if the sentence matches any
  35. syntax of the verb given. If a syntax matches, the orphan vector is
  36. cleared out. If no syntax matches, the appropriate message is printed
  37. in SYN-MATCH (or below). Only the T/Fness of the value is interesting."
  38. <DEFINE EPARSE (PV VB "AUX" VAL)
  39. #DECL ((VAL) ANY (PV) <VECTOR [REST STRING]> (VB) <OR ATOM FALSE>)
  40. <SETG PARSE-CONT <>>
  41. <COND
  42. (<SET VAL <SPARSE .PV .VB>>
  43. <COND (<OR .VB <==? .VAL WIN>> <ORPHAN <>>)
  44. (<SYN-MATCH .VAL>
  45. <ORPHAN <>>
  46. <COND (<==? <2 .VAL> ,BUNCH-OBJ>
  47. <COND (<MEMQ <1 .VAL> ,BUNCHERS>
  48. <PUT <2 .VAL> ,ORAND <1 .VAL>>
  49. <PUT .VAL 1 ,BUNCHER>)
  50. (<OR .VB
  51. <TELL "Multiple inputs cannot be used with '"
  52. 1
  53. <SPNAME <VNAME <1 .VAL>>>
  54. "'.">>
  55. <>)>)
  56. (T)>)>)>>
  57. "SPARSE -- set up parse vector. This is done in two steps.
  58. In the first, each word of the input is looked up in the various
  59. interesting oblists. If a DIRECTION is seen before an ACTION, the parse
  60. wins. Also, if any word is not found, the parse fails. As various parts
  61. of speech are found, variables are set up saying so
  62. In the second, the vector and variables resulting are checked. Any
  63. missing are (attempted to be) set up from the orphans of the last parse.
  64. If they can't be new orphans are generated.
  65. There are three possible results of all this: WIN, which means the
  66. parse is done and no syntax checking is needed; the Parse-Vector, meaning
  67. the parse needs to have syntax checking done; and a FALSE, meaning the parse
  68. has failed."
  69. <DEFINE SPARSE SPAROUT (SV VB
  70. "AUX" (WORDS ,WORDS) (OBJOB ,OBJECT-OBL) (PV ,PRSVEC)
  71. (PVR <PUT <PUT <REST .PV> 1 <>> 2 <>>)
  72. (ACTIONS ,ACTIONS) (DIRS ,DIRECTIONS)
  73. (ORPH ,ORPHANS) (ORFL <OFLAG .ORPH>) (CONTIN <>)
  74. (PRV ,PREPVEC) (HERE ,HERE) (ACTION <>) (PREP <>)
  75. (ADJ <>) (BOBJS ,BUNUVEC) (INBUNCH <>) ATM NPREP
  76. PPREP OBJ LOBJ VAL AVAL)
  77. #DECL ((SV) <VECTOR [REST STRING]> (VB ORFL INBUNCH CONTIN) <OR ATOM FALSE>
  78. (ACTIONS WORDS OBJOB DIRS) OBLIST (PV ORPH PRV PVR) VECTOR
  79. (ATM) <OR ATOM FALSE> (HERE) ROOM (ACTION) <OR FALSE ACTION>
  80. (NPREP PREP) <OR FALSE PREP> (ADJ) <OR FALSE ADJECTIVE> (AVAL) ANY
  81. (LOBJ) ANY (OBJ) <OR FALSE OBJECT> (PPREP) PHRASE
  82. (BOBJS) <UVECTOR [REST OBJECT]>)
  83. <SET VAL
  84. <MAPR <>
  85. <FUNCTION (VV "AUX" (X <1 .VV>))
  86. #DECL ((VV) <VECTOR [REST STRING]> (X) STRING)
  87. <COND
  88. (<EMPTY? .X> <MAPLEAVE T>)
  89. (<==? <1 .X> !\#>)
  90. (<AND <NOT .ACTION> <SET ATM <LOOKUP .X .ACTIONS>>> ;"first verb?"
  91. <SET ACTION ,.ATM>)
  92. (<AND <NOT .ACTION> <SET ATM <LOOKUP .X .DIRS>>>
  93. ;"direction before verb?"
  94. <PUT .PV 1 ,WALK!-WORDS>
  95. <PUT .PV 2 ,.ATM>
  96. <RETURN WIN .SPAROUT> ;"parse is a winner")
  97. (<PROG ()
  98. <COND
  99. (<EMPTY? .X> <MAPLEAVE T>)
  100. (<AND <SET ATM <LOOKUP .X .WORDS>> ;"preposition or adjective?"
  101. <COND (<AND .INBUNCH <PUT <1 .VV> 1 !\#> <>>)
  102. (<TYPE? <SET AVAL ,.ATM> PREP> ;"preposition?"
  103. <COND (.PREP ;"if already have one, lose"
  104. <OR .VB <TELL "Double preposition?">>
  105. <MAPLEAVE <>>)
  106. (<SET PREP .AVAL> ;"else set up prep")>)
  107. (<TYPE? .AVAL ADJECTIVE> ;"adjective?"
  108. <SET ADJ .AVAL>
  109. <NOT <AND .ORFL ;"if had ambig. noun, snarf it"
  110. <SET ATM <ONAME .ORPH>>
  111. ;"bad if 'take x','take red y'?"
  112. <OR <EMPTY? <2 .VV>> <PUT <2 .VV> 1 !\#>>
  113. <SET X <SPNAME .ATM>>>>)
  114. (T ;"what else could it be???")>>)
  115. (<SET ATM <LOOKUP .X .OBJOB>> ;"object?"
  116. <COND
  117. (<SET OBJ <GET-OBJECT .ATM .ADJ>> ;"is object accessible?"
  118. <AND <==? .OBJ ,IT-OBJECT>
  119. <SET OBJ ,LAST-IT>>
  120. <SETG LAST-IT .OBJ>
  121. <COND (<AND <NOT <LENGTH? .VV 2>>
  122. <=? <2 .VV> "AND">
  123. <NOT <EMPTY? <SET X <3 .VV>>>>
  124. <NOT <SET CONTIN <LOOKUP .X .ACTIONS>>>>
  125. <PUT <1 .VV> 1 !\#>
  126. <PUT <2 .VV> 1 !\#>
  127. <PUT <SET BOBJS <BACK .BOBJS>> 1 .OBJ>
  128. <SET ADJ <>>
  129. <SET INBUNCH T>
  130. <SET X <1 <SET VV <REST .VV 2>>>>
  131. <AGAIN>)
  132. (.CONTIN
  133. <PUT .VV 2 <REST <2 .VV> 3>>
  134. <SETG PARSE-CONT <REST .VV 2>>)
  135. (<NOT <EMPTY? .BOBJS>>
  136. <COND (<AND <2 .PV> <==? .PREP #PREP OF!-WORDS>>
  137. <SET PVR <BACK .PVR>>)>
  138. <PUT <1 .VV> 1 !\#>
  139. <SET PREP <>>
  140. <SETG BUNCH <PUT <BACK .BOBJS> 1 .OBJ>>
  141. <SET OBJ ,BUNCH-OBJ>
  142. <SET INBUNCH <>>
  143. <SET BOBJS ,BUNUVEC>)>
  144. <COND (<EMPTY? .PVR>
  145. <OR .VB <TELL "Too many objects specified?">>
  146. <MAPLEAVE <>>)
  147. (<==? .PREP #PREP OF!-WORDS>
  148. <SET PREP <>>
  149. <COND (<==? <2 .PV> .OBJ>)
  150. (<OR .VB <TELL "That doesn't make sense!">>
  151. <MAPLEAVE <>>)>)
  152. (<PUT .PVR
  153. 1
  154. <COND (.PREP
  155. ;"if hanging prep., make a prep. phrase"
  156. <SET PPREP <1 .PRV>>
  157. <SET PRV <REST .PRV>>
  158. <PUT .PPREP 1 .PREP>
  159. <SET PREP <>>
  160. <PUT .PPREP 2 .OBJ>)
  161. (.OBJ)>>
  162. <SET PVR <REST .PVR>>)>
  163. ;"lose, mentioned more than two objects")
  164. (ELSE ;"interpret why can't find/see/access object for loser"
  165. <COND
  166. (<EMPTY? .OBJ>
  167. <OR .VB
  168. <COND (<LIT? .HERE>
  169. <TELL "I can't see any" 0>
  170. <COND (.ADJ
  171. <TELL " " 0 <PRSTR <CHTYPE .ADJ ATOM>>>)>
  172. <TELL " " 1 <PRSTR .ATM> " here.">)
  173. (<TELL "It is too dark in here to see.">)>>)
  174. (<==? .OBJ ,NEFALS2>
  175. <OR .VB
  176. <TELL "I can't reach that from inside the "
  177. 1
  178. <ODESC2 <AVEHICLE ,WINNER>>
  179. ".">>)
  180. (T
  181. <ORPHAN T ;"ambiguous, set up orphan (ONAME slot is giveaway)"
  182. <SET AVAL <OR .ACTION <AND .ORFL <OVERB .ORPH>>>>
  183. <2 .PV>
  184. .PREP
  185. .ATM>
  186. <COND (<NOT .VB>
  187. <TELL "Which " 0 <PRSTR .ATM>>
  188. <COND (.AVAL
  189. <TELL " should I "
  190. 1
  191. <PRLCSTR <VSTR .AVAL>>
  192. "?">)
  193. (<TELL "?">)>)>)>
  194. <MAPLEAVE <>>)>
  195. <SET ADJ <>>
  196. T)
  197. (ELSE ;"inform of unknown word"
  198. <OR .VB <TELL "I don't know the word " 1 .X>>
  199. <MAPLEAVE <>>)>>)>>
  200. .SV>>
  201. <COND (.VAL ;"second phase starts if first won"
  202. <COND (<AND <NOT .ACTION> ;"no verb specified?"
  203. <NOT <SET ACTION ;"here try to pick up orphan verb"
  204. <AND .ORFL <OVERB .ORPH>>>>>
  205. <OR .VB ;"tsk, tsk, no verb"
  206. <COND (<TYPE? <2 .PV> OBJECT> ;"ask about orphan object"
  207. <TELL "What should I do with the "
  208. 1
  209. <ODESC2 <2 .PV>>
  210. "?">)
  211. (<TELL "Huh?">
  212. ;"brilliant response to brilliant input")>>
  213. <ORPHAN T <> <2 .PV>>
  214. <>)
  215. (<AND <PUT .PV 1 .ACTION> ;"stuff winning verb"
  216. .ADJ ;"is there still an adjective about?">
  217. <OR .VB <TELL "Huh?">> <>)
  218. (<AND .ORFL
  219. <SET NPREP <OPREP .ORPH>> ;"orphan prep.?"
  220. <NOT <3 .PV>>
  221. <NOT .PREP>
  222. <==? <1 .PV> <OVERB .ORPH>>
  223. <SET OBJ
  224. <COND (<TYPE? <SET AVAL <2 .PV>> OBJECT> .AVAL)
  225. (<2 .AVAL>)>>
  226. <PUT <SET PPREP <1 .PRV>> 1 .NPREP>
  227. <PUT .PPREP 2 .OBJ>
  228. <COND (<SET OBJ <OSLOT1 .ORPH>> ;"orphan object"
  229. <PUT .PV 2 .OBJ>
  230. <PUT .PV 3 .PPREP>)
  231. (<PUT .PV 2 .PPREP>)>
  232. <>>)
  233. (.PREP ;"handle case of 'pick frob up': make it 'pick up frob'"
  234. <AND <TYPE? <SET LOBJ <1 <BACK .PVR>>> OBJECT>
  235. <TOP <PUT <BACK .PVR>
  236. 1
  237. <PUT <PUT <1 .PRV> 1 .PREP> 2 .LOBJ>>>>)
  238. (.PV ;"win!!!")>)>>
  239. \
  240. "SYN-MATCH -- checks to see if the objects supplied match any of the
  241. syntaxes of the sentence's verb. if none do, and there are several
  242. possibilities, the one marked 'DRIVER' is used to try to snarf orphans
  243. or if all else fails, to make new orphans for next time."
  244. <DEFINE SYN-MATCH SYN-ACT (PV
  245. "AUX" (ACTION <1 .PV>) (OBJS <REST .PV>) (O1 <1 .OBJS>)
  246. (O2 <2 .OBJS>) (DFORCE <>) (DRIVE <>) (GWIM <>) SYNN)
  247. #DECL ((ACTION) ACTION (PV OBJS) VECTOR (DRIVE DFORCE) <OR FALSE SYNTAX>
  248. (O1 O2) <OR FALSE OBJECT PHRASE> (SYNN) VARG (GWIM) <OR FALSE OBJECT>
  249. (SYN-ACT) ACTIVATION)
  250. <MAPF <>
  251. <FUNCTION (SYN)
  252. #DECL ((SYN) SYNTAX)
  253. <COND
  254. (<SYN-EQUAL <SYN1 .SYN> .O1> ;"direct object ok?"
  255. <COND (<SYN-EQUAL <SYN2 .SYN> .O2> ;"indirect object ok?"
  256. <AND <STRNN .SYN ,SFLIP>
  257. ;"make 'give dog bone' become 'give bone to dog'"
  258. <PUT .OBJS 1 .O2> <PUT .OBJS 2 .O1>>
  259. <RETURN ;"syntax a winner, try taking objects"
  260. <TAKE-IT-OR-LEAVE-IT .SYN <PUT .PV 1 <SFCN .SYN>>>
  261. .SYN-ACT>)
  262. (<NOT .O2> ;"no indirect object? might still be okay"
  263. <COND (<STRNN .SYN ,SDRIVER> <SET DFORCE .SYN>)
  264. (ELSE <SET DRIVE .SYN>
  265. ;"last tried is default if no driver")>)>)
  266. (<NOT .O1> ;"no direct object? might still be okay"
  267. <COND (<STRNN .SYN ,SDRIVER> <SET DFORCE .SYN>) (ELSE <SET DRIVE .SYN>)>)>>
  268. <VDECL .ACTION>>
  269. <COND
  270. (<SET DRIVE <OR .DFORCE .DRIVE>> ;"lost for bad syntax"
  271. <COND (<AND <SET SYNN <SYN1 .DRIVE>> ;"here try to fill direct object slot"
  272. <NOT .O1>
  273. <NOT <0? <VBIT .SYNN>>>
  274. <NOT <ORFEO .SYNN .OBJS>> ;"try to fill slot from orphan"
  275. <NOT <SET O1 ;"try to fill unspecified slot from room, etc."
  276. <SET GWIM <GWIM-SLOT 1 .SYNN .ACTION .OBJS>>>>>
  277. <ORPHAN T .ACTION <> <VPREP .SYNN>>
  278. ;"all failed, orphan the verb and prep."
  279. <ORTELL .SYNN .ACTION .GWIM>)
  280. (<AND <SET SYNN <SYN2 .DRIVE>>
  281. ;"here try to fill indirect object slot"
  282. <NOT .O2>
  283. <NOT <0? <VBIT .SYNN>>>
  284. <NOT <GWIM-SLOT 2 .SYNN .ACTION .OBJS>
  285. ;"fill empty from room if can">>
  286. <ORPHAN T .ACTION .O1 <VPREP .SYNN>> ;"all failed, orphan the world"
  287. <ORTELL .SYNN .ACTION .GWIM>)
  288. (ELSE ;"filled both slots, try syntax again"
  289. <TAKE-IT-OR-LEAVE-IT .DRIVE <PUT .PV 1 <SFCN .DRIVE>>>)>)
  290. (ELSE ;"total chomp!"
  291. <TELL "I can't make sense out of that."> <>)>>
  292. "SYN-EQUAL -- takes a VARG and an object or phrase. is the object
  293. acceptable? That is, is the prep. (if any) a match, and is the object ok
  294. (meaning do the OFLAGS slot of the object and the VBIT slot of the verb
  295. agree. Example: the object you ATTACK must be a 'victim'). The VFWIM
  296. slot is used to determine what objects to try to take."
  297. <DEFINE SYN-EQUAL (VARG POBJ "AUX" (VBIT <VBIT .VARG>))
  298. #DECL ((VARG) VARG (POBJ) <OR FALSE PHRASE OBJECT> (VBIT) FIX)
  299. <COND (<TYPE? .POBJ PHRASE>
  300. <AND <==? <VPREP .VARG> <1 .POBJ>> <TRNN <2 .POBJ> .VBIT>>)
  301. (<TYPE? .POBJ OBJECT>
  302. <AND <NOT <VPREP .VARG>> <TRNN .POBJ .VBIT>>)
  303. (<AND <NOT .POBJ> <0? .VBIT>>)>>
  304. \
  305. "TAKE-IT-OR-LEAVE-IT -- finish setup of parse-vector. take objects from room if
  306. allowed, flush prepositions from prepositional phrases. Its value is more or less
  307. ignored by everyone."
  308. <DEFINE TAKE-IT-OR-LEAVE-IT (SYN PV "AUX" (PV1 <2 .PV>) (PV2 <3 .PV>) OBJ)
  309. #DECL ((SYN) SYNTAX (PV) VECTOR (PV1 PV2) <OR FALSE OBJECT PHRASE>
  310. (OBJ) <OR FALSE OBJECT>)
  311. <PROG ()
  312. <PUT .PV
  313. 2
  314. <SET OBJ
  315. <COND (<TYPE? .PV1 OBJECT> .PV1)
  316. (<TYPE? .PV1 PHRASE> <2 .PV1>)>>>
  317. <COND (<==? .OBJ ,BUNCH-OBJ> <SETG BUNCH-SYN .SYN>)
  318. (.OBJ <OR <TAKE-IT .OBJ <SYN1 .SYN>> <RETURN <>>>)>
  319. <PUT .PV
  320. 3
  321. <SET OBJ
  322. <COND (<TYPE? .PV2 OBJECT> .PV2)
  323. (<TYPE? .PV2 PHRASE> <2 .PV2>)>>>
  324. <AND .OBJ <RETURN <TAKE-IT .OBJ <SYN2 .SYN>>>>
  325. T>>
  326. "TAKE-IT -- takes object, parse-vector, and syntax bits, tries to perform a TAKE of
  327. the object from the room. Its value is more or less ignored."
  328. <DEFINE TAKE-IT (OBJ VARG)
  329. #DECL ((OBJ) OBJECT (VARG) VARG)
  330. <COND (<NOT <0? <CHTYPE <ANDB <OGLOBAL .OBJ> ,STAR-BITS> FIX>>>)
  331. (<NOT <VTRNN .VARG ,VRBIT>> <NOT <IN-ROOM? .OBJ>>)
  332. (<NOT <VTRNN .VARG ,VTBIT>>
  333. <COND (<NOT <VTRNN .VARG ,VCBIT>>) (<NOT <IN-ROOM? .OBJ>>)>)
  334. (<NOT <IN-ROOM? .OBJ>>)
  335. (<AND <CAN-TAKE? .OBJ> <SEARCH-LIST <OID .OBJ> <ROBJS ,HERE> <>>>
  336. <DO-TAKE .OBJ>)
  337. (<NOT <VTRNN .VARG ,VCBIT>>)
  338. (<TELL "You can't take the " 1 <ODESC2 .OBJ> "."> <>)>>
  339. "DO-TAKE -- perform a take, returning whether you won"
  340. <DEFINE DO-TAKE (OBJ "AUX" RES (PV ,PRSVEC) (SAV1 <1 .PV>) (SAV2 <2 .PV>))
  341. #DECL ((OBJ) OBJECT (PV) VECTOR (SAV1 SAV2) ANY)
  342. <PUT .PV 1 ,TAKE!-WORDS>
  343. <PUT .PV 2 .OBJ>
  344. <SET RES <TAKE T>>
  345. <PUT .PV 1 .SAV1>
  346. <PUT .PV 2 .SAV2>
  347. .RES>
  348. \
  349. "---------------------------------------------------------------------
  350. GWIM & FWIM -- all this idiocy is used when the loser didn't specify
  351. part of the command because it was 'obvious' what he meant. GWIM is
  352. used to try to fill it in by searching for the right object in the
  353. adventurer's possessions and the contents of the room.
  354. ---------------------------------------------------------------------"
  355. "GWIM-SLOT -- 'get what i mean' for one slot of the parse-vector. takes
  356. a slot number, a syntax spec, an action, and the parse-vector. returns
  357. the object, if it won. seems a lot of pain for so little, eh?"
  358. <DEFINE GWIM-SLOT (FX VARG ACTION OBJS "AUX" OBJ)
  359. #DECL ((FX) FIX (VARG) VARG (ACTION) ACTION (OBJS) VECTOR
  360. (OBJ) <OR FALSE OBJECT>)
  361. <COND (<SET OBJ <GWIM <VFWIM .VARG> .VARG .ACTION>>
  362. <PUT .OBJS .FX .OBJ>
  363. .OBJ)>>
  364. "GWIM -- 'get what i mean'. takes attribute to check, what to check in
  365. (adventurer and/or room), and verb. does a 'TAKE' of it if found,
  366. returns the object."
  367. <DEFINE GWIM (BIT FWORD ACTION
  368. "AUX" (AOBJ? <VTRNN .FWORD ,VABIT>)
  369. (ROBJ? <VTRNN .FWORD ,VRBIT>)
  370. (DONT-CARE? <NOT <VTRNN .FWORD ,VCBIT>>)
  371. (AOBJ <>) ROBJ (AV <AVEHICLE ,WINNER>))
  372. #DECL ((BIT) FIX (FWORD) VARG (ACTION) ACTION
  373. (AOBJ? ROBJ? CARE?) <OR ATOM FALSE>
  374. (AOBJ ROBJ AV) <OR OBJECT FALSE>)
  375. <AND .AOBJ? <SET AOBJ <FWIM .BIT <AOBJS ,WINNER> .DONT-CARE?>>>
  376. <COND (.ROBJ?
  377. <COND (<AND <SET ROBJ <FWIM .BIT <ROBJS ,HERE> .DONT-CARE?>>
  378. <OR <NOT .AV>
  379. <==? .AV .ROBJ>
  380. <MEMQ .ROBJ <OCONTENTS .AV>>
  381. <TRNN .ROBJ ,FINDMEBIT>>>
  382. <COND (<AND <NOT .AOBJ>
  383. <TAKE-IT .ROBJ .FWORD>
  384. .ROBJ>)>)
  385. (<OR .ROBJ <NOT <EMPTY? .ROBJ>>> ,NEFALS)
  386. (.AOBJ)>)
  387. (.AOBJ)>>
  388. "FWIM -- takes object specs, list of objects to look in, and whether or
  389. not we care if can take object. find one that can be manipulated (visible
  390. and takeable, or visible and in something that's visible and open)"
  391. <DEFINE FWIM DWIM (BIT OBJS NO-CARE "AUX" (NOBJ <>))
  392. #DECL ((NO-CARE) <OR ATOM FALSE> (BIT) FIX (OBJS) <LIST [REST OBJECT]>
  393. (NOBJ) <OR FALSE OBJECT>)
  394. <MAPF <>
  395. <FUNCTION (X)
  396. #DECL ((X) OBJECT)
  397. <COND (<AND <OVIS? .X>
  398. <OR .NO-CARE <CAN-TAKE? .X>>
  399. <TRNN .X .BIT>>
  400. <COND (.NOBJ <RETURN ,NEFALS .DWIM>)>
  401. <SET NOBJ .X>)>
  402. <COND
  403. (<AND <OVIS? .X> <OOPEN? .X>>
  404. <MAPF <>
  405. <FUNCTION (X)
  406. #DECL ((X) OBJECT)
  407. <COND (<AND <OVIS? .X> <TRNN .X .BIT>>
  408. <COND (.NOBJ <RETURN ,NEFALS .DWIM>)
  409. (<SET NOBJ .X>)>)>>
  410. <OCONTENTS .X>>)>>
  411. .OBJS>
  412. .NOBJ>
  413. \
  414. "GET-OBJECT -- used to see if an object is accessible. it looks for
  415. an object that can be described by an adjective-noun pair.
  416. Takes atom (from objects oblist), adjective, and verbosity flag.
  417. grovels over: ,STARS; ,HERE; ,WINNER looking for object (looks down to
  418. one level of containment).
  419. returns:
  420. #FALSE () -- if fails because can't find it or it's dark in room
  421. NEFALS = #FALSE (1) -- ambiguous object
  422. NEFALS2 = #FALSE (2) -- can't reach from in vehicle
  423. or
  424. object -- if found it.
  425. "
  426. <DEFINE GET-OBJECT GET-OBJ (OBJNAM ADJ
  427. "AUX" OBJ (OOBJ <>) (HERE ,HERE)
  428. (AV <AVEHICLE ,WINNER>) (CHOMP <>))
  429. #DECL ((OOBJ OBJ AV) <OR OBJECT FALSE> (OBJNAM) ATOM (HERE) ROOM
  430. (ADJ) <OR ADJECTIVE FALSE> (CHOMP) <OR ATOM FALSE>
  431. (OBJL) <OR FALSE <LIST [REST OBJECT]>>)
  432. <COND (<AND <LIT? .HERE>
  433. <SET OBJ <SEARCH-LIST .OBJNAM <ROBJS ,HERE> .ADJ>>>
  434. <COND (<AND .AV
  435. <N==? .OBJ .AV>
  436. <NOT <MEMQ .OBJ <OCONTENTS .AV>>>
  437. <NOT <TRNN .OBJ ,FINDMEBIT>>>
  438. <SET CHOMP T>)
  439. (.OOBJ <RETURN ,NEFALS .GET-OBJ>)
  440. (<SET OOBJ .OBJ>)>)
  441. (<AND <NOT .OBJ> <NOT <EMPTY? .OBJ>>> <RETURN ,NEFALS .GET-OBJ>)>
  442. <COND (.AV
  443. <COND (<SET OBJ <SEARCH-LIST .OBJNAM <OCONTENTS .AV> .ADJ>>
  444. <SET CHOMP <>>
  445. <SET OOBJ .OBJ>)
  446. (<NOT <EMPTY? .OBJ>> <RETURN ,NEFALS .GET-OBJ>)>)>
  447. <COND (<SET OBJ <SEARCH-LIST .OBJNAM <AOBJS ,WINNER> .ADJ>>
  448. <COND (.OOBJ ,NEFALS) (.OBJ)>)
  449. (<NOT <EMPTY? .OBJ>>
  450. ,NEFALS)
  451. (.CHOMP ,NEFALS2)
  452. (.OOBJ)
  453. (<AND <GASSIGNED? .OBJNAM>
  454. <SET OBJ ,.OBJNAM>
  455. <TYPE? .OBJ OBJECT>
  456. <GTRNN .HERE <OGLOBAL .OBJ>>
  457. .OBJ>)>>
  458. "SEARCH-LIST -- search room, or adventurer, or stars, or whatever.
  459. takes object name, list of objects, and verbosity. if finds one
  460. frob under that name on list, returns it. search is to one level of
  461. containment.
  462. "
  463. <DEFINE SEARCH-LIST SL (OBJNAM SLIST ADJ
  464. "OPTIONAL" (FIRST? T)
  465. "AUX" (OOBJ <>) (NEFALS ,NEFALS) NOBJ)
  466. #DECL ((OBJNAM) ATOM (SLIST) <LIST [REST OBJECT]>
  467. (OOBJ NOBJ) <OR FALSE OBJECT> (ADJ) <OR FALSE ADJECTIVE>
  468. (FIRST?) <OR ATOM FALSE> (NEFALS) FALSE)
  469. <MAPF <>
  470. <FUNCTION (OBJ)
  471. #DECL ((OBJ) OBJECT)
  472. <COND (<THIS-IT? .OBJNAM .OBJ .ADJ>
  473. <COND (.OOBJ <RETURN .NEFALS .SL>) (<SET OOBJ .OBJ>)>)>
  474. <COND (<AND <OVIS? .OBJ>
  475. <OR <OOPEN? .OBJ> <TRANSPARENT? .OBJ>>
  476. <OR .FIRST? <TRNN .OBJ ,SEARCHBIT>>>
  477. <COND (<SET NOBJ
  478. <SEARCH-LIST .OBJNAM
  479. <OCONTENTS .OBJ>
  480. .ADJ
  481. <>>>
  482. <COND (.OOBJ <RETURN .NEFALS .SL>)
  483. (<SET OOBJ .NOBJ>)>)
  484. (<==? .NOBJ .NEFALS> <RETURN .NEFALS .SL>)>)>>
  485. .SLIST>
  486. .OOBJ>
  487. \
  488. <SETG ORPHANS [<> <> <> <> <>]>
  489. <DEFINE ORPHAN ("OPTIONAL" (FLAG <>) (ACTION <>) (SLOT1 <>) (PREP <>) (NAME
  490. <>))
  491. #DECL ((FLAG) <OR ATOM FALSE> (NAME) <OR ATOM FALSE>)
  492. <PUT <PUT <PUT <PUT <PUT ,ORPHANS ,ONAME .NAME> ,OPREP .PREP>
  493. ,OSLOT1
  494. .SLOT1>
  495. ,OVERB
  496. .ACTION>
  497. ,OFLAG
  498. .FLAG>>
  499. <DEFINE ORFEO (SYN OBJS "AUX" (ORPH ,ORPHANS) (ORFL <OFLAG .ORPH>) SLOT1)
  500. #DECL ((SYN) VARG (OBJS ORPH) VECTOR (ORFL) <OR ATOM FALSE>
  501. (SLOT1) <OR FALSE PHRASE OBJECT>)
  502. <COND (<NOT .ORFL> <>)
  503. (<SET SLOT1 <OSLOT1 .ORPH>>
  504. <AND <SYN-EQUAL .SYN .SLOT1> <PUT .OBJS 1 .SLOT1>>)>>
  505. <DEFINE ORTELL (VARG ACTION GWIM "AUX" (PREP <VPREP .VARG>) SP)
  506. #DECL ((VARG) VARG (ACTION) ACTION (PREP) <OR FALSE PREP> (SP) STRING
  507. (GWIM) <OR FALSE OBJECT>)
  508. <COND (.PREP
  509. <AND .GWIM
  510. <TELL <VSTR .ACTION> 0 " ">
  511. <TELL <ODESC2 .GWIM> 0 " ">>
  512. <TELL <PRSTR <CHTYPE .PREP ATOM>> 1 " what?">)
  513. (<TELL <VSTR .ACTION> 1 " what?">)>
  514. <>>
  515. \
  516. "PRSTR -- printing routine to print uc/lc atom pname"
  517. <DEFINE PRSTR (ATM "AUX" SP)
  518. #DECL ((ATM) ATOM (SP) STRING)
  519. <FOOSTR <SET SP <SPNAME .ATM>> <BACK ,SCRSTR <LENGTH .SP>> <>>>
  520. <DEFINE PRLCSTR (STR)
  521. #DECL ((STR) STRING)
  522. <FOOSTR .STR <BACK ,LSCRSTR <LENGTH .STR>> T T>>
  523. <SETG SCRSTR <REST <ISTRING 5> 5>>
  524. <SETG LSCRSTR <REST <ISTRING 15> 15>>
  525. <DEFINE FOOSTR (NAM STR "OPTIONAL" (1ST T) (LC <>))
  526. #DECL ((STR NAM) STRING (1ST LC) <OR ATOM FALSE>)
  527. <MAPR <>
  528. <FUNCTION (X Y "AUX" (A <ASCII <1 .X>>))
  529. #DECL ((X Y) STRING (A) FIX)
  530. <COND (<AND <NOT .LC> .1ST <==? .X .NAM>>
  531. <PUT .Y 1 <1 .X>>)
  532. (<OR <L? .A <ASCII !\A>> <G? .A <ASCII !\Z>>>
  533. <PUT .Y 1 <1 .X>>)
  534. (<PUT .Y 1 <ASCII <+ .A 32>>>)>>
  535. .NAM
  536. .STR>
  537. .STR>
  538. \
  539. ;"Here is some code for handling BUNCHes."
  540. <SETG BUNCHER <CHTYPE [BUNCH!-WORDS BUNCHEM] VERB>>
  541. <GDECL (BUNCHER) VERB>
  542. ;
  543. "Action function for BUNCHing.
  544. ,BUNCH = UVECTOR of OBJECTS in the bunch
  545. ,BUNCH-SYN = SYNTAX for this call (for TAKE-IT-OR-LEAVE-IT)
  546. BUNCHEM sets up PRSVEC for each object in the bunch, tries to
  547. do the TAKE, etc. if necessary and calls the VERB function.
  548. "
  549. <DEFINE BUNCHEM ("AUX" (VERB <ORAND ,BUNCH-OBJ>) (VFCN <VFCN .VERB>)
  550. (PV ,PRSVEC) (OBJS ,BUNCH) (SYN ,BUNCH-SYN) (HERE ,HERE))
  551. #DECL ((VERB) VERB (VFCN) RAPPLIC (PV) VECTOR (HERE) ROOM
  552. (OBJS) <UVECTOR [REST OBJECT]> (SYN) SYNTAX)
  553. <PUT .PV 1 .VERB>
  554. <REPEAT ((BUN <REST .OBJS <LENGTH .OBJS>>) OBJ)
  555. #DECL ((BUN) <UVECTOR [REST OBJECT]> (OBJ) OBJECT)
  556. <SET OBJ <1 <SET BUN <BACK .BUN>>>>
  557. <TELL <ODESC2 .OBJ> 0 ":
  558. ">
  559. <PUT .PV 2 .OBJ>
  560. <COND (<TAKE-IT-OR-LEAVE-IT .SYN .PV <>> <APPLY-RANDOM .VFCN>)>
  561. <OR <==? ,HERE .HERE> <RETURN>>
  562. <AND <==? .OBJS .BUN> <RETURN>>>>
  563. "PARSER AUXILIARIES"
  564. <SETG INBUF <ISTRING 100>>
  565. ;"SET UP INPUT ERROR HANDLER TO CAUSE EPARSE TO FALSE OUT"
  566. <SETG PRSVEC <IVECTOR 3 #FALSE ()>>
  567. <DEFINE THIS-IT? (OBJNAM OBJ ADJ)
  568. #DECL ((OBJNAM) ATOM (OBJ) OBJECT (ADJ) <OR FALSE ADJECTIVE>)
  569. <COND (<AND <OVIS? .OBJ>
  570. <OR <==? .OBJNAM <OID .OBJ>> <MEMQ .OBJNAM <ONAMES .OBJ>>>>
  571. <COND (<NOT .ADJ>) (<MEMQ .ADJ <OADJS .OBJ>>)>)>>
  572. <SETG LEXV <IVECTOR 18 '<REST <ISTRING 5> 5>>>
  573. <GDECL (LEXV) <VECTOR [REST STRING]> (BRKS) STRING>
  574. <DEFINE LEX (S
  575. "OPTIONAL" (SX <REST .S <LENGTH .S>>) (SILENT? <>)
  576. "AUX" (BRKS ,BRKS) (V ,LEXV) (TV .V) (S1 .S) (QUOT <>) (BRK !\ ))
  577. #DECL ((S S1 SX BRKS) STRING (SILENT? QUOT) <OR ATOM FALSE>
  578. (VALUE) <OR FALSE VECTOR> (TV V) <VECTOR [REST STRING]>
  579. (BRK) CHARACTER)
  580. <MAPR <>
  581. <FUNCTION (X "AUX" (STR <1 .X>))
  582. #DECL ((X) <VECTOR [REST STRING]> (STR) STRING)
  583. <PUT .X 1 <REST .STR <LENGTH .STR>>>>
  584. .V>
  585. <COND
  586. (<==? <1 .S> !\?> <PUT .V 1 <SUBSTRUC "HELP" 0 4 <BACK <1 .V> 4>>>)
  587. (<REPEAT (SLEN)
  588. #DECL ((SLEN) FIX)
  589. <COND
  590. (<OR <AND <==? <LENGTH .S1> <LENGTH .SX>> <SET BRK !\ >>
  591. <AND <MEMQ <1 .S1> .BRKS> <SET BRK <1 .S1>>>>
  592. <AND <G? <LENGTH .S1> <LENGTH .SX>>
  593. <OR <==? <1 .S1> !\'> <==? <1 .S1> !\">>
  594. <NOT .QUOT>
  595. <SET QUOT T>
  596. <SET V <REST .V>>>
  597. <COND
  598. (<N==? .S .S1>
  599. <COND
  600. (<EMPTY? .V> <OR .SILENT? <TELL "I'm too simple-minded for that.">>)
  601. (<PUT .V
  602. 1
  603. <UPPERCASE <SUBSTRUC .S
  604. 0
  605. <SET SLEN
  606. <MIN <- <LENGTH .S> <LENGTH .S1>>
  607. 5>>
  608. <BACK <1 .V> .SLEN>>>>
  609. <SET V <REST .V>>
  610. <AND <==? .BRK !\,>
  611. <PUT .V 1 <SUBSTRUC "AND" 0 3 <BACK <1 .V> 3>>>
  612. <SET V <REST .V>>>
  613. <AND <L? <LENGTH .V> 17>
  614. <=? <1 <BACK .V>> "AND">
  615. <=? <1 <BACK .V 2>> "AND">
  616. <PUT <SET V <BACK .V>> 1 <REST <1 .V> 3>>>)>)>
  617. <COND (<==? <LENGTH .S1> <LENGTH .SX>>
  618. <COND (<AND <N==? .V ,LEXV> <=? <1 <SET V <BACK .V>>> "AND">>
  619. <PUT .V 1 <REST <1 .V> <LENGTH <1 .V>>>>)>
  620. <RETURN .V>)>
  621. <SET S <REST .S1>>)>
  622. <SET S1 <REST .S1>>>)>
  623. ,LEXV>
  624. <PSETG BRKS "\"' :;.,?!
  625. ">
  626. <DEFINE ANYTHING (S SX)
  627. #DECL ((S SX) STRING)
  628. <MAPR <>
  629. <FUNCTION (X)
  630. <COND (<==? .X .SX> <MAPLEAVE <>>)
  631. (<NOT <MEMQ <1 .X> ,BRKS>> <MAPLEAVE .X>)>>
  632. .S>>
  633. <DEFINE UPPERCASE (STR)
  634. #DECL ((STR) STRING)
  635. <MAPR <>
  636. <FUNCTION (S "AUX" (C <ASCII <1 .S>>))
  637. <COND (<AND <G? .C 96> <L=? .C 122>>
  638. <PUT .S 1 <ASCII <- .C 32>>>)>>
  639. .STR>
  640. .STR>