-
Notifications
You must be signed in to change notification settings - Fork 27
/
reds.zil
1334 lines (1268 loc) · 45.2 KB
/
reds.zil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"REDS file: imitates old parser.
Copyright (C) 1988 Infocom, Inc. All rights reserved."
<ZZPACKAGE "REDS">
<ENTRY RED-SP RED-ADV RED-PART
RED-SV RED-SVN RED-SVNP RED-SVPNPN RED-SVPNN RED-SVNPN RED-SD RED-SVD
RED-PERS RED-VP RED-NP RED-OF RED-QT RED-QN RED-NPP RED-PP
RED-POSS RED-ADJ RED-QUOTE>
<ENTRY RED-O-ADJ RED-O-PP RED-O-NP NUMERIC-ADJ?>
<INCLUDE "BASEDEFS" "FIND" "PBITDEFS" "PDEFS">
<USE "NEWSTRUC" "PARSER" "PMEM" "PSTACK">
<FILE-FLAGS MDL-ZIL? ;ZAP-TO-SOURCE-DIRECTORY?>
<BEGIN-SEGMENT 0>
<DEFMAC ABS ('NUM)
<FORM COND (<FORM L? .NUM 0> <FORM - 0 .NUM>)
(T .NUM)>>
"Generic reduction, which just returns a list of frobs"
<DEFINE RED-FCN ("OPT" N:FIX TYP:FIX)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "ANY">) (T <RFALSE>)>)>
<COND (<==? .N 0> T)
(<==? .N 1>
<POP-PSTACK ,DATA-STACK>)>>
<DEFINE RED-PART RP ("OPT" N:FIX TYP:FIX "AUX" WD)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "?PART">) (T <RFALSE>)>)>
<COND (<==? .N 0>
<RETURN T .RP>)>
<SET WD <POP-PSTACK ,DATA-STACK>>
<COND (<AND <NOT <EQUAL? .WD T ,W?OF>>
<NOT <WORD-TYPE? .WD ,P-PARTICLE-CODE>>>
<RETURN <> .RP>)
(<==? .N 1>
<RETURN .WD .RP>)
(T
<POP-PSTACK ,DATA-STACK>)>>
<DEFINE GET-SYNTAX GS (VA:TABLE NUM "OPT" (PREP 0) (GWIM <>) "AUX" LEN)
<COND (<==? .PREP 1>
<SET PREP 0>)>
<COND (<1? .NUM>
<SET LEN ,VERB-ONE-SYNTAX-LEN ;6>)
(T
<SET LEN ,VERB-TWO-SYNTAX-LEN ;10>)>
<REPEAT ((CT:FIX <ZGET .VA 0>) S2 (P2 <PARSE-PARTICLE2 ,PARSE-RESULT>)
(GWIM-NOW <>)
(SYN <IF-MUDDLE <CHTYPE <ZREST .VA 2> VERB-SYNTAX>
<ZREST .VA 2>>))
<COND (<AND <==? .PREP <SYNTAX-PREP ;1 .SYN 1>>
<OR <1? .NUM>
<EQUAL? .P2
<SET S2 <SYNTAX-GET .SYN ,SYN-PREP 2>>>
<AND <0? .S2>
<1? .P2>>
<AND <T? .GWIM-NOW>
<T? <SET S2 <COND (<1? .NUM> .PREP) (T .S2)>>>
<ZPUT ,GWIM-MSG 0 .S2>>>>
<PARSE-SYNTAX ;3 ,PARSE-RESULT .SYN>
<PARSE-ACTION ;4 ,PARSE-RESULT <SYNTAX-ID .SYN>>
<PARSE-PARTICLE1 ,PARSE-RESULT .PREP>
<RETURN .SYN .GS>)
(<L? <SET CT <- .CT 1>> 1>
<COND (<AND <T? .GWIM>
<F? .GWIM-NOW>>
<SET CT <ZGET .VA 0>>
<SET GWIM-NOW T>
<SET SYN <IF-MUDDLE <CHTYPE <ZREST .VA 2> VERB-SYNTAX>
<ZREST .VA 2>>>
<AGAIN>)
(T
<RETURN <> .GS>)>)
(T
<SET SYN <IF-MUDDLE <CHTYPE <ZREST .SYN .LEN> VERB-SYNTAX>
<ZREST .SYN .LEN>>>)>>>
"Reduction for case of verb with no objects. If OK, win. Otherwise,
try defaulting (and go to case of verb with one object)/orphaning..."
<DEFINE RED-SV ("OPT" N:FIX TYP:FIX "AUX" SYN VERB PART DATA:VERB-DATA OBJ)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "VP-?P">) (T <RFALSE>)>)>
<SET PART <POP-PSTACK ,DATA-STACK>>
<POP-PSTACK ,DATA-STACK>
<COND (<SET VERB <ROOT-VERB <PARSE-VERB ,PARSE-RESULT>>>
<SET DATA <WORD-VERB-STUFF .VERB>>
<COND (<AND <1? .PART>
<L=? 0 <VERB-ZERO .DATA>:FIX>>
;"Verb can take no args, so this flies"
<PARSE-ACTION ,PARSE-RESULT <VERB-ZERO .DATA>>
T ;,PARSE-RESULT)
(<AND <SET SYN <VERB-ONE .DATA>>
<SET SYN <GET-SYNTAX .SYN 1 .PART T>>
<SET OBJ <DETERMINE-OBJ <> 1>>>
<PARSE-OBJ1 ,PARSE-RESULT .OBJ>
T ;,PARSE-RESULT)
(<AND <SET SYN <VERB-TWO .DATA>>
<SET SYN <GET-SYNTAX .SYN 2 .PART T>>
<SET OBJ <DETERMINE-OBJ <> 1>>>
<PARSE-OBJ1 ,PARSE-RESULT .OBJ>
<ZPUT ,ORPHAN-S ,O-OBJECT <NOUN-PHRASE-OBJ1 .OBJ>>
<COND (<SET OBJ <DETERMINE-OBJ <> 2>>
<PARSE-OBJ2 ,PARSE-RESULT .OBJ>
T ;,PARSE-RESULT)>)>)>>
<DEFINE ROOT-VERB (VERB "AUX" DATA)
<COND (<AND <T? <WORD-FLAGS .VERB>>
<SET DATA <WORD-SEMANTIC-STUFF .VERB>>>
<SET VERB .DATA>)>
.VERB>
<DEFINE RED-SVN ("OPT" N:FIX TYP:FIX
"AUX" SYN1 SYN2 VERB PART DATA OBJ OBJ1 OBJ2)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "VP-?P-NP">) (T <RFALSE>)>)>
<SET OBJ <POP-PSTACK ,DATA-STACK>>
<SET PART <POP-PSTACK ,DATA-STACK>>
;<PARSE-PARTICLE1 ,PARSE-RESULT .PART>
<POP-PSTACK ,DATA-STACK> ;"RED-SVNP depends on these POPs"
<COND (<SET VERB <ROOT-VERB <PARSE-VERB ,PARSE-RESULT>>>
<SET DATA <WORD-VERB-STUFF .VERB>>
<COND (<AND <ZERO? <PARSE-PARTICLE2 ,PARSE-RESULT>>
<SET SYN1 <VERB-ONE .DATA>>
<SET SYN1 <GET-SYNTAX .SYN1 1 .PART>>>
;<PARSE-PARTICLE1 ,PARSE-RESULT .PART> ;"SWG 28-Jul-88"
<COND (<NOT <SET OBJ1 <DETERMINE-OBJ .OBJ 1>>>
<PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .OBJ
.PART ;<SYNTAX-SEARCH ;B5 .SYN1 1>>)
(<AND <EQUAL? ,INTDIR <NOUN-PHRASE-OBJ1 .OBJ1>>
<ZAPPLY ,DIR-VERB-WORD?
<PARSE-VERB ,PARSE-RESULT>>
<PUSH-PSTACK ,DATA-STACK <NP-NAME .OBJ>>>
<RED-SD 1 .TYP>)
(T
<PARSE-OBJ1 ,PARSE-RESULT .OBJ1>
,PARSE-RESULT)>)
(<AND <SET SYN2 <VERB-TWO .DATA>>
<SET SYN2 <GET-SYNTAX .SYN2 2 .PART T>>>
;<PARSE-PARTICLE1 ,PARSE-RESULT .PART> ;"SWG 28-Jul-88"
<COND (<NOT <SET OBJ1 <DETERMINE-OBJ .OBJ 1>>>
<PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .OBJ
.PART ;<SYNTAX-SEARCH ;B5 .SYN2 1>>)
(T
<PARSE-OBJ1 ,PARSE-RESULT .OBJ1>
<ZPUT ,ORPHAN-S ,O-OBJECT <NOUN-PHRASE-OBJ1 .OBJ1>>
<COND (<SET OBJ2 <DETERMINE-OBJ <> 2>>
<PARSE-OBJ2 ,PARSE-RESULT .OBJ2>
,PARSE-RESULT)>)>)
;(T
<PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .OBJ
.PART ;<SYNTAX-SEARCH ;B5 .SYN1 1>>)>)>>
<DEFINE RED-SVNP ("OPT" N:FIX TYP:FIX "AUX" PART OBJ)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "VP-NP-P">) (T <RFALSE>)>)>
<SET PART <POP-PSTACK ,DATA-STACK>>
<SET OBJ <POP-PSTACK ,DATA-STACK>>
;"PICK OBJECT UP = PICK UP OBJECT"
<PUSH-PSTACK ,DATA-STACK .PART>
<PUSH-PSTACK ,DATA-STACK .OBJ>
<COND (<NOT <RED-SVN .N .TYP>>
<PUSH-PSTACK ,DATA-STACK <PARSE-VERB ,PARSE-RESULT>>
<PUSH-PSTACK ,DATA-STACK T>
<PARSE-PARTICLE2 ,PARSE-RESULT .PART>
<PUSH-PSTACK ,DATA-STACK .OBJ>
<RED-SVN .N .TYP>)
(T T)>>
<DEFINE RED-SVNPN ("OPT" N:FIX TYP:FIX "AUX" OBJ2 ;PART OBJ1)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "VP-NP-P-NP">)
(T <RFALSE>)>)>
<SET OBJ2 <POP-PSTACK ,DATA-STACK>>
<PARSE-PARTICLE2 ,PARSE-RESULT <POP-PSTACK ,DATA-STACK>>
<SET OBJ1 <POP-PSTACK ,DATA-STACK>>
;<COND (<AND <EQUAL? <PARSE-VERB ,PARSE-RESULT> ,W?SAY>
<EQUAL? <PARSE-PARTICLE2 ,PARSE-RESULT> ,W?TO>
<PMEM? .OBJ1>
<PMEM-TYPE? .OBJ1 NOUN-PHRASE>
<EQUAL? <NOUN-PHRASE-OBJ1 .OBJ1> ,INTQUOTE>>
;"etc."
)>
;<PUSH-PSTACK ,DATA-STACK .PART>
<PUSH-PSTACK ,DATA-STACK .OBJ1>
<PUSH-PSTACK ,DATA-STACK .OBJ2>
<DEC N>
<RED-SVPNN .N .TYP>>
<DEFINE RED-SVPNN ("OPT" N:FIX TYP:FIX "AUX" N1 N2 (PART <>) OBJ1 OBJ2 SYN)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "VP-?P-NP-NP">)
(T <RFALSE>)>)>
<SET N2 <POP-PSTACK ,DATA-STACK>>
<COND (<0? <PARSE-PARTICLE2 ;8 ,PARSE-RESULT>>
<PARSE-PARTICLE2 ;8 ,PARSE-RESULT <OR <ZGET ,GWIM-MSG 0> 1>>)>
<SET N1 <POP-PSTACK ,DATA-STACK>>
<COND (<==? .N 4>
<SET PART <POP-PSTACK ,DATA-STACK>>)>
<COND (<NOT <SET SYN <ROOT-VERB <PARSE-VERB ,PARSE-RESULT>>>>
<PARSER-ERROR 0 ;"No syntax" ,PARSER-ERROR-NOUND>)
(<NOT <SET SYN <VERB-TWO <WORD-VERB-STUFF .SYN>>>>
<PARSER-ERROR 0 ,PARSER-ERROR-TMNOUN>)
(<NOT <SET SYN <GET-SYNTAX .SYN 2 .PART>>>
<PARSER-ERROR 0 ;"No syntax" ,PARSER-ERROR-NOUND>)
(<NOT <SET OBJ1 <DETERMINE-OBJ .N1 1>>>
<PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .N1
.PART ;<SYNTAX-SEARCH ;B5 .SYN 1>>)
(<NOT <SET OBJ2 <DETERMINE-OBJ .N2 2>>>
<PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .N2
.PART ;<SYNTAX-SEARCH ;B9 .SYN 2>>)
(<ZAPPLY ,DIR-VERB-PRSI? .OBJ2>
<PARSER-ERROR 0 ;"Not a direction" ,PARSER-ERROR-NOUND>)
(T
<POP-PSTACK ,DATA-STACK>
<PARSE-OBJ1 ,PARSE-RESULT .OBJ1>
<PARSE-OBJ2 ,PARSE-RESULT .OBJ2>
T)>>
<DEFINE RED-SVPNPN ("OPT" N:FIX TYP:FIX "AUX" N2)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "VP-P-NP-P-NP">)
(T <RFALSE>)>)>
<SET N2 <POP-PSTACK ,DATA-STACK>>
<PARSE-PARTICLE2 ,PARSE-RESULT <POP-PSTACK ,DATA-STACK>>
<PUSH-PSTACK ,DATA-STACK .N2>
<RED-SVPNN <- .N 1> .TYP>>
<DEFINE RED-SD ("OPT" N:FIX TYP:FIX "AUX" V)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "DIR=S">) (T <RFALSE>)>)>
<PARSE-VERB ,PARSE-RESULT <SET V ,W?WALK>>
<GET-SYNTAX <VERB-ONE <WORD-VERB-STUFF .V>> 1 <>>
<SETG P-WALK-DIR <WORD-DIR-ID <POP-PSTACK ,DATA-STACK>>>
;<SETG PRSO ,P-WALK-DIR>
<PARSE-OBJ1 ,PARSE-RESULT <PMEM-ALLOC NOUN-PHRASE
COUNT 1
LENGTH ,NOUN-PHRASE-MIN-LENGTH
OBJ1 ,P-WALK-DIR>>
T ;,PARSE-RESULT>
<DEFINE RED-SVD ("OPT" N:FIX TYP:FIX "AUX" DIR)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "VP-DIR">) (T <RFALSE>)>)>
<SET DIR <POP-PSTACK ,DATA-STACK>>
<COND (<ZAPPLY ,DIR-VERB-WORD? <PARSE-VERB ,PARSE-RESULT>>
<POP-PSTACK ,DATA-STACK>
<PUSH-PSTACK ,DATA-STACK .DIR>
<RED-SD <- .N 1> .TYP>)>>
<DEFINE RED-SP ("OPT" N:FIX TYP:FIX "AUX" A)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "SP">) (T <RFALSE>)>)>
<SET A <POP-PSTACK ,DATA-STACK>>
<DEC N>
<COND (<AND <EQUAL? .N 2 ;3>
<N==? T .A>>
<PARSE-ADV ,PARSE-RESULT <OR <WORD-SEMANTIC-STUFF .A> .A>>)>
<FLUSH-PSTACK ,DATA-STACK .N>
,PARSE-RESULT>
<GLOBAL SEARCH-FLAGS:NUMBER 0>
<DEFINE IREDUCE-EXCEPTION (ENP:PMEM NP:PMEM)
;"Both ENP and NP are NPs"
<COND (<==? <NP-NAME .ENP> ,W?ONE>
;"All books except the red one..."
<NP-NAME .ENP <NP-NAME .NP>>)>
<COND (<NOT <NP-QUANT .ENP>>
<NP-QUANT .ENP ,NP-QUANT-ALL>)>
<SETG SEARCH-FLAGS <BOR ,SEARCH-ALL ;15 ,SEARCH-MANY ;16>>
<DETERMINE-NP 0 0 .ENP>>
<DEFINE REDUCE-EXCEPT-IT (PHR NP)
<COND (<AND <==? 1 <NOUN-PHRASE-COUNT .PHR>>
<==? ,IT <NOUN-PHRASE-OBJ1 .PHR>>>
<COND (<ZERO? ,P-IT-OBJECT>
<PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .NP>)
;(<NOT <VISIBLE? ,P-IT-OBJECT>>
<NOT-HERE ,P-IT-OBJECT>)
(T
<NOUN-PHRASE-OBJ1 .PHR ,P-IT-OBJECT>)>)>>
<DEFINE REDUCE-EXCEPTION RE (PP:PMEM NP:PMEM "AUX"
(ENP:PMEM <PP-NOUN .PP>) NOUN-PHRASE)
<COND
(<PMEM-TYPE? .ENP NP>
;"Just one thing"
<COND (<SET NOUN-PHRASE <IREDUCE-EXCEPTION .ENP .NP>>
;"Returns a noun-phrase, which we can then stuff into
an NPP to be stuffed into the EXCEPT slot"
<REDUCE-EXCEPT-IT .NOUN-PHRASE .ENP>
<NP-EXCEPT .NP <PMEM-ALLOC NPP
NOUN .ENP
NOUN-PHRASE .NOUN-PHRASE>>
.NP)>)
(T
;"NPP"
<REPEAT (RES (NNP:<OR PMEM FALSE> .ENP) (GOOD <>) BAD)
<COND (<SET RES <IREDUCE-EXCEPTION <SET BAD <NPP-NOUN .NNP>> .NP>>
<SET GOOD T>
<REDUCE-EXCEPT-IT .RES .BAD>
<NPP-NOUN-PHRASE .NNP .RES>)>
<COND (<NOT <SET NNP <NPP-NEXT .NNP>>>
<COND (<T? .GOOD>
<NP-EXCEPT .NP .ENP>
<RETURN .NP .RE>)
(T
<RETURN <PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .BAD> .RE>)>)>>)>>
<CONSTANT P-NO-INSIDE "No inside">
<CONSTANT P-NO-SURFACE "No surface">
<CONSTANT P-NOTHING "Nothing">
<CONSTANT PREP-BIT <ITABLE 3 0>>
<DEFINE REDUCE-LOCATION RL
(PP:PMEM
"OPT" (SYN:<OR FALSE VERB-SYNTAX> <>)
(WHICH:<OR FIX FALSE> <>)
"AUX" (SEARCH <COND (.SYN
<COND (<==? .WHICH 1>
<SYNTAX-SEARCH .SYN 1>)
(T
<SYNTAX-SEARCH .SYN 2>)>)>)
(TEST <COND (.SYN
<COND (<==? .WHICH 1>
<SYNTAX-FIND .SYN 1>)
(T
<SYNTAX-FIND .SYN 2>)>)>)
(PREP:VWORD <PP-PREP .PP>)
(NP:PMEM <PP-NOUN .PP>) (RLOC <>)
(BIT 0) (MSG <>) "VALUE" <OR PMEM FALSE>)
<COND (<NOT .SEARCH> <SET SEARCH <BOR ,SEARCH-HELD ,SEARCH-ON-GROUND> ;5>)>
;<COND (<NOT .TEST> <SET TEST ,TEST-PREP>)>
<COPYT ,PREP-BIT 0 6>
<COND
(<EQUAL? .PREP ,W?BUT ,W?EXCEPT>
<RETURN <> .RL>)
;(<EQUAL? .PREP ,W?UNDER>
<SET BIT ,F?HAS-UNDER>
<SET MSG ,P-NO-UNDERSIDE>)
;(<EQUAL? .PREP ,W?ABOUT ,W?FOR ,W?TO>)
(<EQUAL? .PREP ,W?IN ,W?INSIDE>
<SET BIT ,CONTBIT>
<SET MSG ,P-NO-INSIDE>)
(<EQUAL? .PREP ,W?ON ,W?OFF>
<SET BIT ,SURFACEBIT>
<SET MSG ,P-NO-SURFACE>)
;(<EQUAL? .PREP ,W?BEHIND>
<SET BIT ,F?HAS-BEHIND>
<SET MSG ,P-NO-BACKSIDE>)
(<EQUAL? .PREP ,W?FROM ;,W?OF>
<SET BIT ,SURFACEBIT>
<ZPUT ,PREP-BIT 1 ,PERSONBIT>
<ZPUT ,PREP-BIT 2 ,CONTBIT>
<SET MSG ,P-NOTHING>)
(T
<RETURN <> .RL>)>
<ZPUT ,PREP-BIT 0 .BIT>
<COND (<PMEM-TYPE? .NP NP>
<COND (<SET RLOC <NP-LOC .NP>:PMEM>
<SET RLOC <NOUN-PHRASE-OBJ1 <LOCATION-OBJECT .RLOC>:PMEM>>)>
<MAKE-FINDER 'FINDER ,FINDER
'FIND-APPLIC .TEST
'FIND-RES ,SEARCH-RES
'FIND-ADJS <NP-ADJS .NP>
'FIND-NOUN <NP-NAME .NP>
'FIND-NUM <NUMERIC-ADJ? .NP>>
<SET SEARCH <FIND-OBJECTS <COND (<NOT .RLOC> .SEARCH) (T 0)>
.RLOC>>
;<FIND-NUM ,FINDER 0>
<COND (.SEARCH
<SET RLOC <PMEM-ALLOC NOUN-PHRASE
COUNT 1
LENGTH ,NOUN-PHRASE-MIN-LENGTH
OBJ1 <FIND-RES-OBJ1 ,SEARCH-RES>
NP1 .NP>>
<PMEM-ALLOC LOCATION PREP .PREP OBJECT .RLOC>)
(<0? <FIND-RES-COUNT ,SEARCH-RES>:FIX>
<PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .NP .PREP ;.SEARCH>)
(<READY-TO-DISAMBIGUATE? .NP>
<PARSER-ERROR 0 ,PARSER-ERROR-ORPH-NP
.NP <PARSE-VERB ,PARSE-RESULT>>)
;(T
<PARSER-ERROR ,P-TOO-MANY-OBJECTS-FOR-LOCATION 0 .NP>)>)>>
;<DEFINE DO-TEST-PREP DTP (OBJ:OBJECT VERB:VWORD "AUX" (BIT:TABLE ,PREP-BIT))
<COND (<0? <ZGET .BIT 0>:FIX> T)
(T
<REPEAT ((CT 0))
<COND (<FSET? .OBJ <ZGET .BIT .CT>:FIX> <RETURN T .DTP>)>
<COND (<OR <G? <SET CT <+ .CT 1>> 2>
<0? <ZGET .BIT .CT>:FIX>>
<RETURN <> .DTP>)>>)>>
<COND (<GASSIGNED? DO-TEST-PREP> <SETG TEST-PREP <TABLE ,DO-TEST-PREP>>)>
"Decide what object(s) OBJ refers to. If OBJ is false, we're looking to
GWIM something. Otherwise, it's one of NP, NPP, or NOUN-PHRASE. In the
last case, just return it, because it's already been reduced."
<DEFINE DETERMINE-OBJ DO (OBJ:<OR FALSE PMEM> NUM:FIX "OPT" (PICK <>)
"AUX" (VAL <>) RES (COUNT:FIX 0)
(SYN:VERB-SYNTAX <PARSE-SYNTAX ;3 ,PARSE-RESULT>)
(S-FLAGS:FIX
<COND (<==? .NUM 1> <SYNTAX-SEARCH ;B5 .SYN 1>)
(T <SYNTAX-SEARCH ;B9 .SYN 2>)>)
(SEARCH-ACT:FIX
<COND (<==? .NUM 1> <SYNTAX-FIND ;B4 .SYN 1>)
(T <SYNTAX-FIND ;B8 .SYN 2>)>))
<COND (<NOT .OBJ> ;"Get What I Mean!"
<MAKE-FINDER 'FINDER ,FINDER
'FIND-APPLIC .SEARCH-ACT
'FIND-FLAGS ,FIND-FLAGS-GWIM
'FIND-SYNTAX .SYN
'FIND-WHICH .NUM
'FIND-RES ,SEARCH-RES>
<COND (<T? .PICK>
<FIND-QUANT ,FINDER ,NP-QUANT-ALL>
;<SET S-FLAGS <BOR .S-FLAGS ,SEARCH-ALL>>)>
<COND (<OR <AND <EQUAL? .SEARCH-ACT ,ROOMSBIT>
<FIND-RES-OBJ1 ,SEARCH-RES ,ROOMS>>
<AND <T? .S-FLAGS>
<OR <FIND-OBJECTS .S-FLAGS>
<AND .PICK <FIND-RES-COUNT ,SEARCH-RES>>>
<ZPUT ,GWIM-MSG 0 <COND (<1? .NUM>
<SYNTAX-PREP .SYN 1>)
(T
<SYNTAX-PREP .SYN 2>)>>
<ZPUT ,GWIM-MSG 1 <FIND-RES-OBJ1 ,SEARCH-RES>>>>
;"Found one thing, so be happy"
;<FIND-NUM ,FINDER 0>
<SET RES <PMEM-ALLOC NOUN-PHRASE
LENGTH ,NOUN-PHRASE-MIN-LENGTH
COUNT 1
;FLAGS ;,NP-FLAG-MULTI
OBJ1 <FIND-RES-OBJ1 ,SEARCH-RES>
NP1 <>>>)
(T
;"This will return an appropriate lossage so the
parser will know to continue."
<ZPUT ,ORPHAN-S ,O-VERB <PARSE-VERB ,PARSE-RESULT>>
<ZPUT ,ORPHAN-S ,O-LEXPTR
<COND (<0? ,P-LEN>
<ZREST ,TLEXV ;,P-RUNNING <* 2 ,P-LEXELEN>>)
(T ,TLEXV ;,P-RUNNING)>>
<ZPUT ,ORPHAN-S ,O-SYNTAX <PARSE-SYNTAX ,PARSE-RESULT>>
<ZPUT ,ORPHAN-S ,O-WHICH .NUM>
<ZPUT ,ORPHAN-S ,O-PART <PARSE-PARTICLE1 ,PARSE-RESULT>>
<ZPUT ,ORPHAN-S ,O-OBJECT
<NOUN-PHRASE-OBJ1 <PARSE-OBJ1 ,PARSE-RESULT>>>
<COND (<SET VAL <PARSE-CHOMPER ,PARSE-RESULT>>
<SET VAL <NOUN-PHRASE-OBJ1 .VAL>>)>
<ZPUT ,ORPHAN-S ,O-SUBJECT .VAL>
<RETURN <PARSER-ERROR 0 ,PARSER-ERROR-ORPH-S
<PARSE-OBJ1 ,PARSE-RESULT>>
.DO>)>)
(<PMEM-TYPE? .OBJ NOUN-PHRASE>
;"Already a winner, so just return it"
<RETURN .OBJ .DO>)
(<PMEM-TYPE? .OBJ NP>
<SETG SEARCH-FLAGS .S-FLAGS>
<DETERMINE-NP 0 ;.SEARCH-ACT .NUM .OBJ>)
(<0? <ANDB .S-FLAGS ,SEARCH-MANY ;16>>
<PARSER-ERROR 0 ,PARSER-ERROR-NOMULT
.NUM <PARSE-VERB ,PARSE-RESULT>>)
(T
;"Do each noun phrase in turn, since we can take multiple objects"
<SETG SEARCH-FLAGS .S-FLAGS>
<REPEAT ((NO .OBJ) (CT <>) PTR)
<COND (<SET PTR <DETERMINE-NP 0 ;.SEARCH-ACT .NUM .NO T>>
;"Remember how many objects we have"
<SET COUNT <+ .COUNT
<NOUN-PHRASE-COUNT
<NPP-NOUN-PHRASE .NO:PMEM>:PMEM>>>
;"And how many real objects we have"
<COND (<ZERO? .CT>
<SET PTR <REST-TO-SLOT .PTR NOUN-PHRASE-OBJ1>>
<REPEAT ((CNT .COUNT))
<COND (<DLESS? CNT 0>
<RETURN>)
(<NOT <EQUAL? ,NOT-HERE-OBJECT
<ZGET .PTR 0>>>
<SET CT T>
<RETURN>)
(T <SET PTR <ZREST .PTR 4>>)>>)>
<COND (<NOT <SET NO <NPP-NEXT .NO:PMEM>>>
<COND (<ZERO? .CT>
<RETURN <> .DO>)>
<RETURN>)>)
(T
<RETURN <> .DO>)>>
;"Build a single noun phrase"
<SET RES <PMEM-ALLOC NOUN-PHRASE
;FLAGS ;,NP-FLAG-MULTI
LENGTH <+ ,NOUN-PHRASE-MIN-LENGTH
<* .COUNT 2> -2>
COUNT .COUNT>>
;"Copy everything into the single noun phrase"
<REPEAT ((NO .OBJ) (RR <REST-TO-SLOT .RES NOUN-PHRASE-OBJ1>)
PHRASE TMP)
<SET PHRASE <NPP-NOUN-PHRASE .NO:PMEM>>
<SET TMP <* 4 <NOUN-PHRASE-COUNT .PHRASE>:FIX>>
<COPYT <REST-TO-SLOT .PHRASE NOUN-PHRASE-OBJ1> .RR .TMP>
<SET RR <ZREST .RR .TMP>>
<COND (<NOT <SET NO <NPP-NEXT .NO:PMEM>>>
<RETURN>)>>
.RES)>>
<DEFINE CHECK-DIR-ADJS (ADJS:PMEM)
<REPEAT ((AV <REST-TO-SLOT .ADJS ADJS-COUNT 1>)
(CT <ADJS-COUNT .ADJS>) ADJ PT)
<COND (<L? <SET CT <- .CT 1>> 0>
<RETURN>)
(<AND <WORD-TYPE? <SET ADJ <ZGET .AV .CT>> ,P-DIR-CODE>
<SET PT <GETPT ,HERE <WORD-DIR-ID .ADJ>>>
<EQUAL? <PTSIZE .PT> ,DEXIT>>
<ZPUT .AV .CT ,W?NO.WORD>
<COND (<NOT <MATCH-OBJECT <GET .PT ,DEXITOBJ> ,FINDER T>>
<ZPUT .AV .CT .ADJ>
<RETURN>)>
<ZPUT .AV .CT .ADJ>)>>>
<DEFINE NUMERIC-ADJ? (NP:PMEM "AUX" ADJS (VAL 0))
<COND (<SET ADJS <NP-ADJS .NP>>
<REPEAT ((AV <REST-TO-SLOT .ADJS ADJS-COUNT 1>) (CT <ADJS-COUNT .ADJS>)
ADJ)
<COND (<L? <SET CT <- .CT 1>> 0>
<RETURN>)
(<EQUAL? <SET ADJ <ZGET .AV .CT>> ,W?INT.NUM>
<REPEAT ((VV <NP-LEXEND .NP> ;,TLEXV))
<COND (<EQUAL? .ADJ <ZGET .VV 0>>
<SET VAL <ZGET .VV 1>>
<RETURN>)
(<G? ,P-LEXV <SET VV <ZBACK .VV ,P-LEXELEN>>>
<RETURN>)>>)>>
.VAL)>>
;<CONSTANT FIND-OWNER:TABLE <TABLE (LENGTH) 0 0>>
<VOC "HIMSELF" NOUN>
;<VOC "ITSELF" NOUN>
<IFN-P-PS-ADV <VOC "HERSELF" NOUN>>
<DEFINE DETERMINE-NP DN (SEARCH-ACT:<OR FIX TABLE> WHICH:FIX OBJ:PMEM
"OPT" (MULTI <>)
"AUX" (SYN:<OR VERB-SYNTAX FALSE>
<COND (<0? .WHICH> <>)
(T <PARSE-SYNTAX ,PARSE-RESULT>)>)
(ROBJ:PMEM .OBJ) (RLOC:<OR FALSE PMEM> <>) ;RNP
QUANT:<OR FIX FALSE> OWNER
(RES <>) COUNT:FIX)
<COND (<PMEM-TYPE? .OBJ NPP>
<SET ROBJ <NPP-NOUN .OBJ>>)>
<COND (<SET RLOC <NP-LOC .ROBJ>>
<SET RLOC <LOCATION-OBJECT .RLOC>:PMEM>
;<SET RNP <NOUN-PHRASE-NP1 .RLOC>>
<SET RLOC <NOUN-PHRASE-OBJ1 .RLOC>>)>
<SET QUANT <NP-QUANT .ROBJ>>
<COND (<AND .QUANT
<G? .QUANT ,NP-QUANT-A>
<0? <ANDB ,SEARCH-FLAGS ,SEARCH-MANY ;16>>>
<RETURN <PARSER-ERROR 0 ,PARSER-ERROR-NOMULT
.WHICH <PARSE-VERB ,PARSE-RESULT>>
.DN>)>
<COND (<AND <OR <SET OWNER <NP-OF .ROBJ>>
<AND <SET OWNER <NP-ADJS .ROBJ>>
<SET OWNER <ADJS-POSS .OWNER>>>
;<SET OWNER .RNP>
;<AND <SET OWNER <NP-LOC .ROBJ>>
<SET OWNER <LOCATION-OBJECT .OWNER>>
<SET OWNER <NOUN-PHRASE-NP1 .OWNER>>>>
<PMEM? .OWNER>>
;<COND (<PMEM-TYPE? .OWNER NOUN-PHRASE>
<SET OWNER <NOUN-PHRASE-NP1 .OWNER>>)>
;<FIND-RES-COUNT ,OWNER-SR-HERE 0>
;<FIND-RES-COUNT ,OWNER-SR-THERE 0>
<MAKE-FINDER 'FINDER ,FINDER
'FIND-APPLIC .SEARCH-ACT
;'FIND-QUANT ;<NP-QUANT .OWNER>
'FIND-SYNTAX .SYN
'FIND-WHICH .WHICH
'FIND-RES ,SEARCH-RES
'FIND-ADJS <NP-ADJS .OWNER>
'FIND-NUM <NUMERIC-ADJ? .OWNER>
'FIND-NOUN <NP-NAME .OWNER>
'FIND-OF <NP-OF .OWNER> ;<OR <NP-OF .ROBJ> .RNP>
;'FIND-EXCEPTIONS ;<NP-EXCEPT .OWNER>>
<FIND-RES-COUNT ,SEARCH-RES 0>
<FIND-RES-NEXT ,SEARCH-RES <>>
<FIND-OBJECTS ,SEARCH-ALL> ;"Find owner in HERE"
<COPYT ,SEARCH-RES ,OWNER-SR-HERE <* 2 ,FIND-RES-LENGTH>>
<FIND-RES-COUNT ,SEARCH-RES 0>
<FIND-RES-NEXT ,SEARCH-RES <>>
<FIND-OWNERS ,OWNERS> ;"Search for other owners."
<COPYT ,SEARCH-RES ,OWNER-SR-THERE <* 2 ,FIND-RES-LENGTH>>)>
<COND (<EQUAL? <NP-NAME .ROBJ> ,W?HIMSELF> ;"ASK TROLL ABOUT HIMSELF"
<COND (<AND <EQUAL? 2 .WHICH>
<SET COUNT <PARSE-OBJ1 ,PARSE-RESULT>>
<SET COUNT <NOUN-PHRASE-OBJ1 .COUNT>>
<FSET? .COUNT ,PERSONBIT>>
<SET RES .COUNT>
<IFN-P-PS-ADV
<COND (<FSET? .COUNT ,FEMALE ;,FEMALEBIT>
<SET RES ,P-HIM-OBJECT>)>>)
(T
<SET RES ,P-HIM-OBJECT>)>)>
<IFN-P-PS-ADV
<COND (<EQUAL? <NP-NAME .ROBJ> ,W?HERSELF ;%<VOC "HERSELF" NOUN>>
<COND (<AND <EQUAL? 2 .WHICH>
<SET COUNT <PARSE-OBJ1 ,PARSE-RESULT>>
<SET COUNT <NOUN-PHRASE-OBJ1 .COUNT>>
<FSET? .COUNT ,PERSONBIT>
<FSET? .COUNT ,FEMALE ;,FEMALEBIT>>
<SET RES .COUNT>)
(T
<SET RES ,P-HER-OBJECT>)>)>>
<COND (<T? .RES>
<RETURN <PMEM-ALLOC NOUN-PHRASE
LENGTH ,NOUN-PHRASE-MIN-LENGTH
COUNT 1
OBJ1 .RES
NP1 .ROBJ>
.DN>)>
<MAKE-FINDER 'FINDER ,FINDER
'FIND-APPLIC .SEARCH-ACT
'FIND-QUANT .QUANT
'FIND-SYNTAX .SYN
'FIND-WHICH .WHICH
'FIND-RES ,SEARCH-RES
'FIND-ADJS <NP-ADJS .ROBJ>
'FIND-NUM <NUMERIC-ADJ? .ROBJ>
'FIND-NOUN <NP-NAME .ROBJ>
'FIND-OF <OR <NP-OF .ROBJ> ;.RNP>
'FIND-EXCEPTIONS <NP-EXCEPT .ROBJ>>
<FIND-OBJECTS ,SEARCH-FLAGS .RLOC>
<COND (<AND <ZERO? <FIND-RES-COUNT ,SEARCH-RES>>
<T? <NP-ADJS .ROBJ>>>
<CHECK-DIR-ADJS <NP-ADJS .ROBJ>>)>
<COND (<AND <ZERO? <SET COUNT <FIND-RES-COUNT ,SEARCH-RES>>>
<SET RLOC <NP-NAME .ROBJ>>
<T? <ANDB ,PLURAL-FLAG <WORD-FLAGS .RLOC>>>>
<NP-QUANT .ROBJ ,NP-QUANT-ALL ;,NP-QUANT-PLURAL>
<NP-NAME .ROBJ <WORD-SEMANTIC-STUFF .RLOC>>
<AGAIN>)
(<ZERO? .COUNT>
<COND (<OR <T? .MULTI>
<ZAPPLY ,NOT-HERE-VERB?
<PARSE-ACTION ,PARSE-RESULT>>>
<SET RES <PMEM-ALLOC NOUN-PHRASE
LENGTH ,NOUN-PHRASE-MIN-LENGTH
COUNT 1
OBJ1 ,NOT-HERE-OBJECT
NP1 .ROBJ>>)>)
(<OR <1? .COUNT>
<T? .QUANT>
<SET RES <ZAPPLY <GETP <FIND-RES-OBJ1 ,SEARCH-RES>
,P?GENERIC>
,SEARCH-RES ,FINDER>>
;"Protocol: returns .OBJ if that's the one to use,
,NOT-HERE-OBJECT if 'are none',
[,ROOMS if case was handled and msg TELLed,]
<> if WHICH-PRINT should be called"
;<AND <SET RES ,P-IT-OBJECT>
<NOT <NOT-IN-FIND-RES? .RES ,SEARCH-RES T>>>>
<COND (<EQUAL? .RES ,NOT-HERE-OBJECT ;,ROOMS>
;<THROW ,PARSER-RESULT-DEAD ,PARSE-SENTENCE-ACTIVATION>
<RETURN <PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .OBJ> .DN>)
(<T? .RES>
<SET COUNT 1>
<FIND-RES-COUNT ,SEARCH-RES 1>
<FIND-RES-NEXT ,SEARCH-RES <>>
<FIND-RES-OBJ1 ,SEARCH-RES
<COND (<EQUAL? .RES ,HERE> ,GLOBAL-HERE)
(T .RES)>>)>
<SET RES <PMEM-ALLOC NOUN-PHRASE
;FLAGS ;<COND (.QUANT ,NP-FLAG-MULTI)
(T 0)>
LENGTH <+ <* .COUNT 2>
,NOUN-PHRASE-MIN-LENGTH
-2>
COUNT .COUNT>>
<COND (<OR <SET SYN <NP-OF .ROBJ>> ;"Store owner found."
<AND <SET SYN <NP-ADJS .ROBJ>>
<SET SYN <ADJS-POSS .SYN>>>
;<SET SYN .RNP>>
<COND (<NOT <OBJECT? .SYN>>
<SET SYN <FIND-RES-OWNER ,SEARCH-RES>>
<COND (<NP-OF .ROBJ>
<NP-OF .ROBJ .SYN>)
(T ;<NP-ADJS .ROBJ>
<ADJS-POSS <NP-ADJS .ROBJ> .SYN>)
;(T
<NOUN-PHRASE-NP1 <LOCATION-OBJECT <NP-LOC .ROBJ>>
.SYN>)>)>)>
<COND (<SET SYN <DETERMINE-NP-XFER .COUNT .ROBJ ,SEARCH-RES
<REST-TO-SLOT .RES NOUN-PHRASE-OBJ1>>>
<NOUN-PHRASE-COUNT .RES <- .COUNT .SYN>>)>)
(<READY-TO-DISAMBIGUATE? .ROBJ>
<RETURN <PARSER-ERROR 0 ,PARSER-ERROR-ORPH-NP
.ROBJ <PARSE-VERB ,PARSE-RESULT>>
.DN>)>
<COND (<AND .RES <PMEM-TYPE? .OBJ NPP>>
<NPP-NOUN-PHRASE .OBJ .RES>)>
;<FIND-NUM ,FINDER 0>
.RES>
<DEFINE FIND-OWNERS (TBL)
<REPEAT (OOBJ (LEN <ZGET .TBL 0>))
<COND (<L? .LEN 1>
<RETURN>)
(<OBJECT? <SET OOBJ <ZGET .TBL .LEN>>>
<COND (<NOT <MATCH-OBJECT .OOBJ ,FINDER T>>
<RETURN>)>)
(T ;"It's another table!"
<FIND-OWNERS .OOBJ>)>
<SET LEN <- .LEN 1>>>>
<DEFINE READY-TO-DISAMBIGUATE? RTD (NP "AUX" PTR NOUN)
<COND (<AND <SET PTR <NP-LEXEND .NP>>
<SET NOUN <NP-NAME .NP>>>
<REPEAT ()
<COND (<==? .NOUN <ZGET .PTR 0>>
<RETURN .PTR .RTD>)
(<G? ,P-LEXV <SET PTR <- .PTR ,LEXV-ELEMENT-SIZE-BYTES>>>
<RETURN <> .RTD>)>>)>>
<DEFINE DETERMINE-NP-XFER ACT (COUNT ROBJ SRES DV "AUX" CT V)
<SET CT <FIND-RES-SIZE .SRES>>
<SET V <REST-TO-SLOT .SRES FIND-RES-OBJ1>>
<REPEAT ()
<COND (<G? .CT .COUNT>
<SET CT .COUNT>)>
<SET COUNT <- .COUNT .CT>>
<REPEAT (TMP (NUM 0))
<COND (<SET TMP <ZGET .V 0>>
<ZPUT .DV 0 .TMP>
<ZPUT .DV 1 .ROBJ>)
(T
<INC NUM>)>
<SET DV <ZREST .DV 4>>
<SET V <ZREST .V 2>>
<COND (<L? <SET CT <- .CT 1>> 1>
<COND (<ZERO? <SET SRES <FIND-RES-NEXT .SRES>>>
<RETURN .NUM .ACT>)>
<SET CT ,FIND-RES-MAXOBJ ;<OBJLIST-SIZE .SRES>>
<SET V <REST-TO-SLOT .SRES OBJLIST-OBJ1>>
<COND (<G? .CT .COUNT>
<SET CT .COUNT>)>
<SET COUNT <- .COUNT .CT>>)>>>>
<DEFINE RED-O-ADJ ("OPT" N:FIX TYP:FIX)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "O-ADJ">)
(T <RFALSE>)>)>
<COND (<T? ,P-OFLAG>
<COPYT ,O-LEXV ,G-LEXV ,LEXV-LENGTH-BYTES>
<COPYT ,O-INBUF ,G-INBUF <+ 1 ,INBUF-LENGTH>>
<ZPUT ,OOPS-TABLE ,O-START <ZGET ,OOPS-TABLE ,O-AGAIN>>
;<COND (<ZERO? <ZGET ,G-LEXV ,P-OFLAG>> ;"PARSER-ERROR-ORPH-S"
<ZPUT ,G-LEXV ,P-OFLAG ,W?NO.WORD>)>
<INSERT-ADJS <POP-PSTACK ,DATA-STACK>>
;<SETG P-OFLAG <>>
<COPY-INPUT T>
<THROW ,PARSER-RESULT-AGAIN ,PARSE-SENTENCE-ACTIVATION>)>>
<DEFINE RED-O-PP ("OPT" N:FIX TYP:FIX "AUX" PP A PREP)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "O-PP">) (T <RFALSE>)>)>
<COND (<AND <T? <SET PP <ABS ,P-OFLAG>>>
<EQUAL? ,W?NO.WORD ;0 <ZGET ,O-LEXV .PP>>
<SET A <ZGET ,O-LEXV <- .PP ,P-LEXELEN>>>
<SET PP <POP-PSTACK ,DATA-STACK>>
<OR <AND <==? .N 1> ;<PMEM-TYPE? .PP PP>
;<EQUAL? .A <PP-PREP .PP>>>
<AND ;<PMEM-TYPE? .PP NP>
<SET PREP <POP-PSTACK ,DATA-STACK>> ;<EQUAL? .A >>>>
;<ZPUT ,O-LEXV .PP ,W?NO.WORD>
<COPYT ,O-LEXV ,G-LEXV ,LEXV-LENGTH-BYTES>
<COPYT ,O-INBUF ,G-INBUF <+ 1 ,INBUF-LENGTH>>
<ZPUT ,OOPS-TABLE ,O-START <ZGET ,OOPS-TABLE ,O-AGAIN>>
<INSERT-NP ;.PP <COND (<EQUAL? .A .PREP> 1) (T 0)>>
;<SETG P-OFLAG <>>
<COPY-INPUT T>
<THROW ,PARSER-RESULT-AGAIN ,PARSE-SENTENCE-ACTIVATION>)>>
<DEFINE INSERT-NP ("OPT" (NUM 0) (NP <>) "AUX" (GPTR <ABS ,P-OFLAG>) PPTR TMP)
<COND (<SET TMP <PARSE-VERB-LEXV ,PARSE-RESULT>>
<SET PPTR <ZREST .TMP <* .NUM <* 2 ,P-LEXELEN>>>>
<SET TMP <+ 1 </ <- ,TLEXV .TMP> ,LEXV-ELEMENT-SIZE-BYTES>>>)
(T
<COND ;(.NP
<SET PPTR <NP-LEXBEG .NP>> ;"unreliable"
<SET TMP <+ 1 </ <- <NP-LEXEND .NP> .PPTR>
,LEXV-ELEMENT-SIZE-BYTES>>>)
(T
<SET PPTR <ZGET ,OOPS-TABLE ,O-START>
;<REST-TO-SLOT ,P-LEXV LEXV-START>>
<SET TMP <ZGET ,OOPS-TABLE ,O-LENGTH> ;,P-OLEN>)>
<SET PPTR <ZREST .PPTR <* .NUM <* 2 ,P-LEXELEN>>>>)
;(T
<SET PPTR <ZREST ,P-LEXV
<* 2 <+ ,P-LEXSTART <* .NUM ,P-LEXELEN>>>>>
<SET TMP <GETB ,P-LEXV ,P-LEXWORDS>>)>
<SET NUM <- .TMP .NUM>>
<MAKE-ROOM-FOR-TOKENS <+ -1 .NUM> ,G-LEXV .GPTR>
;<PUTB ,G-LEXV ,P-LEXWORDS <+ -1 .NUM <GETB ,G-LEXV ,P-LEXWORDS>>>
<REPEAT ()
<COND (<DLESS? NUM 0> <RETURN>)>
<INBUF-ADD <LEXV-WORD-LENGTH .PPTR>
<LEXV-WORD-OFFSET .PPTR>
<SET TMP <+ 3 <* .GPTR 2>>>>
<SET TMP <ZGET .PPTR 0>>
<ZPUT ,G-LEXV .GPTR .TMP>
<COND (<EQUAL? .TMP ,W?INT.NUM ,W?INT.TIM>
<ZPUT ,G-LEXV <+ 1 .GPTR> <ZGET .PPTR 1>>)>
<SET GPTR <+ .GPTR ,LEXV-ELEMENT-SIZE>>
<SET PPTR <+ .PPTR ,LEXV-ELEMENT-SIZE-BYTES>>>>
<DEFINE TEST-SR ACT (NP "AUX" A (CT 0) (LEN <FIND-RES-COUNT ,ORPHAN-SR>))
<COND (<ZERO? .LEN>
<RETURN <> .ACT>)
(<WORD-TYPE? <SET A <NP-NAME .NP>> ,P-QUANT-CODE>
<RETURN .A .ACT>)
(<ZERO? <SET A <NP-ADJS .NP>>>
<SET A <PMEM-ALLOC ADJS LEXPTR <NP-LEXBEG .NP>>>)
(<NOT <G? ,ADJS-MAX-COUNT <SET CT <ADJS-COUNT .A>>>>
<RETURN <> .ACT>)>
<ZPUT <REST-TO-SLOT .A ADJS-COUNT 1> .CT <NP-NAME .NP>>
<ADJS-COUNT .A <+ 1 .CT>>
<FIND-ADJS ,FINDER .A>
<FIND-NUM ,FINDER <NUMERIC-ADJ? .NP>>
<FIND-NOUN ,FINDER <NP-NAME ,ORPHAN-NP>>
<FIND-RES-COUNT ,SEARCH-RES 0>
<FIND-RES-NEXT ,SEARCH-RES <>>
<REPEAT ((VEC <REST-TO-SLOT ,ORPHAN-SR FIND-RES-OBJ1>)
(SZ <FIND-RES-SIZE ,ORPHAN-SR>)
(REM .LEN))
<COND (<NOT <MATCH-OBJECT <ZGET .VEC 0> ,FINDER T>>
<RETURN .A .ACT>)
;(T <SET LEN <- .LEN 1>>)>
<COND (<L? <SET REM <- .REM 1>> 1>
<RETURN>)
(<L? <SET SZ <- .SZ 1>> 1>
<COND (T ;<ZERO? <SET SR <FIND-RES-NEXT ,ORPHAN-SR>>>
<RETURN>)>
;<SET SZ ,FIND-RES-MAXOBJ ;<OBJLIST-SIZE ,ORPHAN-SR>>
;<SET VEC <REST-TO-SLOT ,ORPHAN-SR OBJLIST-NEXT>>)
(T <SET VEC <ZREST .VEC 2>>)>>
<COND (<NOT <0? .CT>>
<ADJS-COUNT .A .CT>)>
<COND (<NOT <0? <FIND-RES-COUNT ,SEARCH-RES>>>
.A)>>
<DEFINE RED-O-NP ("OPT" N:FIX TYP:FIX "AUX" A NP (PP <>))
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "O-NP">) (T <RFALSE>)>)>
<COND (<EQUAL? .N 2>
<SET PP <POP-PSTACK ,DATA-STACK>>)>
<SET NP <POP-PSTACK ,DATA-STACK>>
<COND (<AND <PMEM-TYPE? .NP NOUN-PHRASE>
<EQUAL? <NOUN-PHRASE-OBJ1 .NP> ,INTQUOTE>>
<SET NP <NOUN-PHRASE-NP1 .NP>>
<COND (<ZERO? ,P-OFLAG>
<SET PP </ <- <NP-LEXBEG .NP> ,P-LEXV> 2>>
<MAKE-ROOM-FOR-TOKENS 1 ,G-LEXV .PP>
<ZPUT ,G-LEXV .PP ,W?SAY>
<COPY-INPUT>
<THROW ,PARSER-RESULT-AGAIN ,PARSE-SENTENCE-ACTIVATION>)>)>
<COND (<T? ,P-OFLAG>
<COND (<AND <ZERO? .PP>
<WORD-TYPE? <NP-NAME .NP> ,P-ADJ-CODE>
;<ZERO? <NP-LOC .NP>>
<ZERO? <NP-QUANT .NP>>
<SET A <TEST-SR .NP>>> ;"Try as adjective instead."
<PUSH-PSTACK ,DATA-STACK .A>
<RED-O-ADJ 1 .TYP> ;"Never returns?"
<RFALSE>)>
<COPYT ,O-LEXV ,G-LEXV ,LEXV-LENGTH-BYTES>
<COPYT ,O-INBUF ,G-INBUF <+ 1 ,INBUF-LENGTH>>
<SET N <ABS ,P-OFLAG>>
<COND (<EQUAL? ,W?NO.WORD ;0 <ZGET ,G-LEXV .N>>
;"PARSER-ERROR-ORPH-S: delete NO.WORD?"
;<PUTB ,G-LEXV ,P-LEXWORDS <- <GETB ,G-LEXV ,P-LEXWORDS> 1>>
<INSERT-NP 0 .NP>)
(T
<PROG ((A1 <>))
<COND (<SET A <NP-NAME .NP>>
<ZPUT ,G-LEXV .N .A>
<SET A <NP-LEXEND .NP>>
<INBUF-ADD <LEXV-WORD-LENGTH .A>
<LEXV-WORD-OFFSET .A>
<+ 3 <* .N 2>>>)>
<COND (<SET A <NP-ADJS .NP>>
<INSERT-ADJS .A>)>
<COND (<T? .PP>
;<SET PP <NP-LOC .NP>>
<MAKE-ROOM-FOR-TOKENS 2 ,G-LEXV <+ .N ,P-LEXELEN>>
<ZPUT ,G-LEXV <+ .N ,P-LEXELEN> <LOCATION-PREP .PP>>
<SET A <LOCATION-OBJECT .PP>>
<COND (<PMEM-TYPE? .A NOUN-PHRASE>
<SET A <NOUN-PHRASE-NP1 .A>>)
(<PMEM-TYPE? .A NPP>
<SET A <NPP-NOUN .A>>)>
<ZPUT ,G-LEXV <+ .N <* 2 ,P-LEXELEN>> <NP-NAME .A>>)>
<COND (<AND <SET A <NP-QUANT .NP>>
;<T? <NP-NAME .NP>>>
<PROG ((PTR .N))
<REPEAT (WD)
<COND (<G? 0 <SET PTR <- .PTR ,P-LEXELEN>>>
<SET PTR <OR .A1 .N>>
<MAKE-ROOM-FOR-TOKENS 1 ,G-LEXV .PTR>
<RETURN>)
(<OR <EQUAL? <SET WD <ZGET ,G-LEXV .PTR>>
,W?THE>
<WORD-TYPE? .WD ,P-QUANT-CODE>>
<RETURN>)
(<WORD-TYPE? .WD ,P-ADJ-CODE>
<SET A1 .PTR>)
(T
<SET PTR <OR .A1 .N>>
<MAKE-ROOM-FOR-TOKENS 1 ,G-LEXV .PTR>
<RETURN>)>>
<ZPUT ,G-LEXV .PTR <GET-QUANTITY-WORD .A>>>)>>)>
<ZPUT ,OOPS-TABLE ,O-START <ZGET ,OOPS-TABLE ,O-AGAIN>>
;<SETG P-OFLAG <>>
<COPY-INPUT ;T>
<THROW ,PARSER-RESULT-AGAIN ,PARSE-SENTENCE-ACTIVATION>)>>
<DEFINE RED-PERS ACT ("OPT" N:FIX TYP:FIX "AUX" X:PMEM)
;<COND (<NOT <ASSIGNED? N>>
<IFFLAG (P-DEBUGGING-PARSER <PRINTR "PERS">) (T <RFALSE>)>)>
<COND (<NOT <EQUAL? .N 2 3>>
T)
(<OR <AND <==? <SET X <POP-PSTACK ,DATA-STACK>> ,W?COMMA>
<EQUAL? .N 2>>
<AND <==? .X ,W?TO>
;<EQUAL? .N 3>>>
<SET X <POP-PSTACK ,DATA-STACK>>
<COND (<EQUAL? .N 3>
<COND ;(<NOT <ZAPPLY ,ASKING-VERB-WORD?
<POP-PSTACK ,DATA-STACK>>>
<RETURN <> .ACT>)
(<NOT <WORD-TYPE? <ZGET ,P-RUNNING 0> ,P-VERB-CODE>>
<RETURN <> .ACT>)>)>
<HACK-TELL .X>)>>
<DEFINE HACK-TELL ACT (X "AUX" NP)
<PARSE-VERB ,PARSE-RESULT ,W?TELL>
<GET-SYNTAX <VERB-ONE <WORD-VERB-STUFF ,W?TELL>> 1 <>>
<COND (<NOT <SET NP <DETERMINE-OBJ .X 1>>>
<RETURN <PARSER-ERROR 0 ,PARSER-ERROR-NOOBJ .X> .ACT>)>
<PARSE-VERB-LEXV ,PARSE-RESULT ,TLEXV>
<PARSE-CHOMPER ,PARSE-RESULT .NP>
<SET X <NOUN-PHRASE-OBJ1 .NP>>
<COND (<EQUAL? .X ,WINNER ,PLAYER ,ME>
T)
<IFN-P-PS-ADV
(<EQUAL? .X ,YOU>
T)>
(T
<IGNORE-FIRST-WORD ,W?YOU>
<COND (<L? ,P-LEN 1>
<SETG P-CONT <>>)
(T
<SETG P-CONT ,TLEXV>)>
<COND (<OR <EQUAL? ,M-FATAL <HACK-TELL-1 .NP>>
<ZERO? ,P-CONT>>
<SETG P-CONT -1>
<THROW ,PARSER-RESULT-DEAD
,PARSE-SENTENCE-ACTIVATION>)>
;<SETG WINNER <PARSE-CHOMPER ,PARSE-RESULT>>)>
T>
<DEFINE HACK-TELL-1 ACT (NP "AUX" X NUM CT)
<SETG PRSO-NP <NOUN-PHRASE-NP1 .NP>>
<SET X <NOUN-PHRASE-OBJ1 .NP>>
<COND (<L? 1 <SET CT <NOUN-PHRASE-COUNT .NP>>>
<COND (<L=? .CT <SET NUM <NOUN-PHRASE-FLAGS .NP>>>
<RETURN <> .ACT>)>
<NOUN-PHRASE-FLAGS .NP <+ 1 .NUM>>
<SETG PRSO-NP <ZGET <REST-TO-SLOT .NP NOUN-PHRASE-NP1>
<* 2 .NUM>>>
<SET X <ZGET <REST-TO-SLOT .NP NOUN-PHRASE-OBJ1>
<* 2 .NUM>>>
<TELL D .X ":|">)>
<IF-P-BE-VERB
<SETG PRSQ <>>
<SETG PRSS <>>>
<SET X <PERFORM ,V?TELL .X>>
<PARSE-ACTION ,PARSE-RESULT 0 ;"for DONT-UNDERSTAND">
.X>