-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathparser.zil
1719 lines (1622 loc) · 49.9 KB
/
parser.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
"PARSER file for NEW PARSER
Copyright (C) 1988 Infocom, Inc. All rights reserved."
<ZZPACKAGE "PARSER">
<ENTRY PARSER PARSE-SENTENCE PARSE-IT PARSER-ERROR TLEXV P-OFLAG P-WALK-DIR
;" P-PRSO P-PRSI PRSA PRSO PRSI">
<RENTRY DEBUG-PARSER>
<RENTRY ACCESSIBLE?
BUZZER-WORD?
GLOBAL-OBJECTS
LAST-PSEUDO-LOC
LIT
LIT?
ONBIT
OPENBIT
P-INBUF
P-LEXV
P-NUMBER
P?THINGS
PERFORM
PERSONBIT
PLAYER
PRINT-VOCAB-WORD
SEARCHBIT
;SPECIAL-ADJ-CHECK
SPECIAL-CONTRACTION?
SURFACEBIT
TAKEBIT
TELL-CTHE
TELL-THE
TITLE-ABBR?
TRANSBIT
TRYTAKEBIT
;VEHBIT
VERBOSITY
VISIBLE?
WINNER>
<INCLUDE "BASEDEFS" "PBITDEFS" "PDEFS" "SYMBOLS">
<USE "PSTACK" "PMEM">
<FILE-FLAGS MDL-ZIL? CLEAN-STACK?>
<BEGIN-SEGMENT 0>
<COMPILATION-FLAG-DEFAULT P-APOSTROPHE-BREAKS-WORDS T>
<COMPILATION-FLAG-DEFAULT P-BE-VERB <>>
;<COMPILATION-FLAG-DEFAULT P-DEBUGGING-PARSER T>
<DEFAULTS-DEFINED
BE-PATIENT
BEG-PARDON
BUZZER-WORD?
;CANT-UNDO
CONTBIT
EXCLUDE-HERE-OBJECT?
INVALID-OBJECT?
INVISIBLE
LIT?
MOBY-FIND?
NARTICLEBIT
NUMBER?
ONBIT
OPENBIT
P-NO-MEM-ROUTINE
PERSONBIT
PLAYER
;PRINT-VOCAB-WORD
PSEUDO-OBJECTS
READ-INPUT
ROOMSBIT
SEARCH-IN-LG?
SEARCHBIT
;SPECIAL-ADJ-CHECK
SPECIAL-CONTRACTION?
STATUS-LINE
SURFACEBIT
TAKEBIT
TELL-CTHE
TELL-GWIM-MSG
TELL-THE
TITLE-ABBR?
TOUCHBIT
TRANSBIT
TRYTAKEBIT
UNKNOWN-WORD
;VEHBIT>
<COND (<NOT <GASSIGNED? DEBUG-PARSER>> <SETG DEBUG-PARSER <>>)>
<DEFAULT-DEFINITION CONTBIT T>
<DEFAULT-DEFINITION INVISIBLE T>
<DEFAULT-DEFINITION NARTICLEBIT T>
<DEFAULT-DEFINITION ONBIT T>
<DEFAULT-DEFINITION OPENBIT T>
<DEFAULT-DEFINITION PERSONBIT T>
<DEFAULT-DEFINITION PLAYER T>
<DEFAULT-DEFINITION ROOMSBIT T>
<DEFAULT-DEFINITION SEARCHBIT T>
<DEFAULT-DEFINITION SURFACEBIT T>
<DEFAULT-DEFINITION TAKEBIT T>
<DEFAULT-DEFINITION TOUCHBIT T>
<DEFAULT-DEFINITION TRANSBIT T>
<DEFAULT-DEFINITION TRYTAKEBIT T>
;<DEFAULT-DEFINITION VEHBIT T>
<DEFAULT-DEFINITION BEG-PARDON
<DEFINE BEG-PARDON () <TELL "[I beg your pardon?]" CR>>>
<DEFAULT-DEFINITION UNKNOWN-WORD
<DEFINE UNKNOWN-WORD (RLEXV "AUX" X)
<COND (<SET X <NUMBER? .RLEXV>>
.X)
(T
<TELL "[I don't know the word \"">
<ZPUT ,OOPS-TABLE ,O-PTR </ <- .RLEXV ,P-LEXV> 2>>
<WORD-PRINT .RLEXV>
<TELL ".\"]" CR>
<IFN-P-BE-VERB <COUNT-ERRORS 1>>
<THROW ,PARSER-RESULT-DEAD ,PARSE-SENTENCE-ACTIVATION>)>>>
<DEFINE WORD-PRINT (PTR "OPT" (LEN <LEXV-WORD-LENGTH .PTR>)
(OFFS <LEXV-WORD-OFFSET .PTR>))
<REPEAT ()
<COND (<L? <SET LEN <- .LEN 1>> 0> <RETURN>)
(T
<TELL C <GETB ,P-INBUF .OFFS>>
<SET OFFS <+ .OFFS 1>>)>>>
<IFFLAG (LONG-WORDS
<DEFINE PRINT-VOCAB-WORD (WD "AUX" TMP)
<COND (<SET TMP <INTBL? .WD <ZREST ,LONG-WORD-TABLE 2>
</ <ZGET ,LONG-WORD-TABLE 0> 2>
*204*>>
<PRINT <ZGET .TMP 1>>)
(<NOT <EQUAL? .WD ,W?INT.NUM ,W?INT.TIM>>
<PRINTB .WD>)>>)
(T
<DEFMAC PRINT-VOCAB-WORD!- ('WD) <FORM PRINTB .WD>>)>
<DEFAULT-DEFINITION MOBY-FIND?
<DEFINE MOBY-FIND? (SEARCH)
<COND (<OR <AND <NOT <0? <ANDB .SEARCH ,SEARCH-MOBY ;128>>>
<0? <ANDB .SEARCH ,SEARCH-MUST-HAVE>>>
<BAND ,PAST-TENSE <WORD-FLAGS <PARSE-VERB ,PARSE-RESULT>>>>
T)>>>
<DEFMAC IF-SHORT ('EXPR1 "OPT" 'EXPR2)
<COND (<L=? ,NUMBER-WORD-CLASSES 15>
<COND (<AND .EXPR1 <N==? .EXPR1 '<>>> .EXPR1)>)
(<ASSIGNED? EXPR2> .EXPR2)>>
<DEFINE NP-SAVE (ROBJ "AUX" TMP)
<COPYT ,SEARCH-RES ,ORPHAN-SR <* 2 ,FIND-RES-LENGTH>>
<COPYT .ROBJ ,ORPHAN-NP <* 2 <+ 1 ,NP-LENGTH>>>
<COND (<T? <SET TMP <NP-LOC .ROBJ>>>
<COPYT <LOCATION-OBJECT .TMP>
,ORPHAN-NP2
<* 2 <+ 1 ,NOUN-PHRASE-MIN-LENGTH>>>
<NP-LOC ,ORPHAN-NP ,ORPHAN-NP2>)
(<T? <SET TMP <NP-OF .ROBJ>>>
<COPYT .TMP ,ORPHAN-NP2 <* 2 <+ 1 ,NP-LENGTH>>>
<NP-OF ,ORPHAN-NP ,ORPHAN-NP2>)
(<T? <SET TMP <NP-EXCEPT .ROBJ>>>
<COPYT .TMP ,ORPHAN-NP2 <* 2 <+ 1 ,NP-LENGTH>>>
<NP-EXCEPT ,ORPHAN-NP ,ORPHAN-NP2>)>
<COND (<T? <SET TMP <NP-ADJS .ROBJ>>>
<COPYT .TMP ,ORPHAN-ADJS <* 2 <+ 1 <+ 4 ,ADJS-MAX-COUNT>>>>
<NP-ADJS ,ORPHAN-NP ,ORPHAN-ADJS>
<COND (<AND <L=? 0 <SET TMP <ADJS-POSS .TMP>>>
<L=? .TMP ,LAST-OBJECT>>
<ADJS-POSS ,ORPHAN-ADJS .TMP>)
(T
;<T? <SET TMP <ADJS-POSS .TMP>>>
<COPYT .TMP ,ORPHAN-NP2 <* 2 <+ 1 ,NP-LENGTH>>>
<ADJS-POSS ,ORPHAN-ADJS ,ORPHAN-NP2>)>)
(T
<NP-ADJS ,ORPHAN-NP 0>)>
,ORPHAN-NP>
<DEFINE PARSER-ERROR ("OPT" (STR:<OR STRING FALSE> <>)
(CLASS:<OR FIX FALSE> <>) (OTHER:ANY <>) (OTHER2:ANY <>)
"AUX" RP)
<COND (<NOT ,CURRENT-REDUCTION>
;"Died in parser itself--incomprehensible sentence")
(<OR <G? ,ERROR-PRIORITY
<SET RP <REDUCTION-ERR-PRIORITY ,CURRENT-REDUCTION>>>
<AND <EQUAL? ,ERROR-PRIORITY .RP>
<OR <AND <NOT <EQUAL? .CLASS ,PARSER-ERROR-NOUND>>
<EQUAL? <ZGET ,ERROR-ARGS 1>
,PARSER-ERROR-NOUND>>
<EQUAL? .CLASS ,PARSER-ERROR-ORPH-NP>
<AND <EQUAL? .CLASS ,PARSER-ERROR-NOOBJ
,PARSER-ERROR-ORPH-S>
<EQUAL? <ZGET ,ERROR-ARGS 1>
,PARSER-ERROR-NOUND
;,PARSER-ERROR-TMNOUN>>>>>
<SETG ERROR-PRIORITY .RP>
<SETG ERROR-STRING .STR>
<COND (.CLASS
<ZPUT ,ERROR-ARGS 0 3>
<ZPUT ,ERROR-ARGS 1 .CLASS>
<ZPUT ,ERROR-ARGS 2 .OTHER>
<ZPUT ,ERROR-ARGS 3 .OTHER2>
<COND (<PMEM? .OTHER>
<COND (<PMEM-TYPE? .OTHER NOUN-PHRASE>
<SET OTHER <NOUN-PHRASE-NP1 .OTHER>>)>
<COND (<PMEM-TYPE? .OTHER NP>
<ZPUT ,ERROR-ARGS 2 <NP-SAVE .OTHER>>)>)>)
(T
<ZPUT ,ERROR-ARGS 0 0>)>)>
<>>
<CONSTANT STATE-STACK <ALLOCATE-PSTACK>>
<CONSTANT SPLIT-STACK <ALLOCATE-PSTACK>>
<CONSTANT DATA-STACK <ALLOCATE-PSTACK>>
<MSETG LEXV-LENGTH 59 ;39>
<MSETG LEXV-LENGTH-BYTES <+ 2 <* 4 ,LEXV-LENGTH>>>
<CONSTANT P-LEXV
<ITABLE ,LEXV-LENGTH (LEXV) 0 #BYTE 0 #BYTE 0>> "current input"
<CONSTANT G-LEXV
<ITABLE ,LEXV-LENGTH (LEXV) 0 #BYTE 0 #BYTE 0>> "previous for OOPS & G"
<CONSTANT O-LEXV
<ITABLE ,LEXV-LENGTH (LEXV) 0 #BYTE 0 #BYTE 0>> "previous for orphan"
<CONSTANT M-LEXV
<ITABLE ,LEXV-LENGTH (LEXV) 0 #BYTE 0 #BYTE 0>> "more cmds after G"
<MSETG INBUF-LENGTH <+ 1 ,LEXV-LENGTH>>
<CONSTANT P-INBUF <ITABLE ,INBUF-LENGTH (BYTE LENGTH) 0>>
<CONSTANT G-INBUF <ITABLE ,INBUF-LENGTH (BYTE LENGTH) 0>>
<CONSTANT O-INBUF <ITABLE ,INBUF-LENGTH (BYTE LENGTH) 0>>
<CONSTANT M-INBUF <ITABLE ,INBUF-LENGTH (BYTE LENGTH) 0>>
<MSETG P-LEXWORDS 1> "# of valid entries in LEXV (byte)"
<MSETG P-LEXSTART 1> "First LEXV entry (word)"
<MSETG P-LEXELEN 2> "Words/LEXV entry"
<CONSTANT OOPS-TABLE <TABLE <> <> <> <> <>>>
<MSETG O-START 0> "word pointer to sentence start in P-LEXV"
<MSETG O-LENGTH 1> "number of unparsed tokens in P-LEXV"
<MSETG O-END 2> "byte pointer to first free byte in G-INBUF"
<MSETG O-PTR 3> "word pointer to unknown token in P-LEXV"
<MSETG O-AGAIN 4> "word pointer to sentence start in O-LEXV"
<GLOBAL WINNER:OBJECT PLAYER>
<GLOBAL P-OFLAG:NUMBER 0>
<GLOBAL P-NUMBER:NUMBER 0>
<SETG CURRENT-REDUCTION <>>
<SETG PARSER-RESULT <>>
<SETG P-WALK-DIR <>>
<SETG TLEXV 0>
<SETG OTLEXV 0>
<GLOBAL M-PTR:NUMBER 0>
<GLOBAL M-LEN:NUMBER 0>
<CONSTANT ERROR-ARGS:TABLE <ITABLE 4 ;7 <>>>
<GLOBAL ERROR-STRING:STRING <>>
<GLOBAL ERROR-PRIORITY:NUMBER 0>
<ADD-WORD "AGAIN" MISCWORD>
<ADD-WORD "G" MISCWORD>
<ADD-WORD "OOPS" MISCWORD>
<ADD-WORD "O" MISCWORD>
;<IF-UNDO <GLOBAL P-CAN-UNDO:NUMBER 0>>
<GLOBAL P-LEN:NUMBER 0> "number of tokens yet to be parsed"
<GLOBAL LIT:OBJECT <>> "source of light, 0=dark"
<DEFAULT-DEFINITION LIT?
<DEFINE LIT? ("OPT" (RM ,HERE) (RMBIT T) "AUX" OHERE (LT <>))
;<COND (<NOT .RM> <SET RM ,HERE>)>
<SET OHERE ,HERE>
<SETG HERE .RM>
<COND (<AND .RMBIT
<FSET? .RM ,ONBIT>>
<SET LT ,HERE>)
(<AND <FSET? ,WINNER ,ONBIT>
<HELD? ,WINNER .RM>>
<SET LT ,WINNER>)
(T
<FIND-RES-COUNT ,SEARCH-RES 0>
<FIND-RES-NEXT ,SEARCH-RES <>>
<FIND-APPLIC ,FINDER ,ONBIT>
<FIND-FLAGS ,FINDER ,FIND-FLAGS-GWIM>
;<MAKE-FINDER 'FINDER ,FINDER
'FIND-APPLIC ,ONBIT
'FIND-RES ,SEARCH-RES
'FIND-FLAGS ,FIND-FLAGS-GWIM>
<COND (<EQUAL? .OHERE .RM>
<FIND-DESCENDANTS ,WINNER
<BOR ,FD-INCLUDE? ,FD-SEARCH? ,FD-NEST? ;,FD-NOTOP?>;7>
<COND (<AND <NOT <EQUAL? ,WINNER ,PLAYER>>
<IN? ,PLAYER .RM>>
<FIND-DESCENDANTS ,PLAYER
<BOR ,FD-INCLUDE? ,FD-SEARCH? ,FD-NEST?
;,FD-NOTOP?> ;7>)>)>
<COND (<0? <FIND-RES-COUNT ,SEARCH-RES>:FIX>
<COND (<AND <NOT <IN? <LOC ,WINNER> ,ROOMS>>
;<FSET? <LOC ,WINNER> ,VEHBIT>
<NOT <FSET? <LOC ,WINNER> ,OPENBIT>>>
<FIND-DESCENDANTS <LOC ,WINNER>
<BOR ,FD-INCLUDE? ,FD-SEARCH? ,FD-NEST?
;,FD-NOTOP?> ;7>)>
<FIND-DESCENDANTS .RM <BOR ,FD-INCLUDE? ,FD-SEARCH?
,FD-NEST? ;,FD-NOTOP?> ;7>)>
<COND (<L? 0 <FIND-RES-COUNT ,SEARCH-RES>:FIX>
<SET LT <FIND-RES-OBJ1 ,SEARCH-RES>>)>)>
<SETG HERE .OHERE>
.LT>>
<DEFAULT-DEFINITION STATUS-LINE
<DEFINE INIT-STATUS-LINE ()
<SPLIT 1>
<SCREEN ,S-WINDOW>
<CURSET 1 1>
<HLIGHT ,H-INVERSE>
<ERASE 1> ;<PRINT-SPACES <LOWCORE SCRH>>
<HLIGHT ,H-NORMAL>
<SCREEN ,S-TEXT>
<RTRUE>>
<GLOBAL OLD-HERE:OBJECT <>>
<DEFINE UPDATE-STATUS-LINE ()
<SCREEN ,S-WINDOW>
<HLIGHT ,H-INVERSE>
<COND (<NOT <EQUAL? ,HERE ,OLD-HERE>>
<SETG OLD-HERE ,HERE>
<CURSET 1 1> ;"Erase old desc."
<ERASE 1> ;<PRINT-SPACES <LOWCORE SCRH>>
<CURSET 1 1>
<TELL D ,HERE>)>
<CURSET 1 <- <LOWCORE SCRH>
<+ <DIGITS ,SCORE> <DIGITS ,MOVES>>>>
<TELL N ,SCORE C !\/ N ,MOVES>
<HLIGHT ,H-NORMAL>
<SCREEN ,S-TEXT>
<RTRUE>>
<DEFINE DIGITS (N "AUX" (D 1))
<COND (<L? .N 0>
<SET D <+ 1 .D>> ;"negative sign"
<SET N <- 0 .N>>)>
<REPEAT ()
<SET N </ .N 10>>
<COND (<0? .N>
<RETURN>)
(T
<SET D <+ 1 .D>>)>>
.D>
>
<DEFAULT-DEFINITION READ-INPUT
<DEFINE READ-INPUT ()
<COND (T ;<OR <CHECK-EXTENDED? XZIP>
<CHECK-EXTENDED? YZIP>>
<PUTB ,P-INBUF 1 0>)>
<ZREAD ,P-INBUF ,P-LEXV>
<COND (T ;<CHECK-EXTENDED? YZIP>
<SCRIPT-INBUF>)>>
<ROUTINE SCRIPT-INBUF ("AUX" BUF (CNT 0) (N <GETB ,P-INBUF 1>) CHR)
<DIROUT ,D-SCREEN-OFF>
<SET BUF <REST ,P-INBUF>>
<REPEAT ()
<COND (<IGRTR? CNT .N> <RETURN>)
(ELSE
<SET CHR <GETB .BUF .CNT>>
<COND (<AND <G=? .CHR !\a>
<L=? .CHR !\z>>
<PRINTC <- .CHR 32>>)
(ELSE <PRINTC .CHR>)>)>>
<CRLF>
<DIROUT ,D-SCREEN-ON>>>
<IFFLAG (<AND P-BE-VERB P-APOSTROPHE-BREAKS-WORDS>
<CONSTANT P-QB-WORDS-1
<PLTABLE <VOC "ARE"> <VOC "CAN"> <VOC "COULD"> <VOC "DO">
<VOC "DOES"> <VOC "DID"> <VOC "HE"> <VOC "I">
<VOC "IS"> <VOC "IT"> ;<VOC "MAY"> ;<VOC "MIGHT">
;<VOC "MUST"> ;<VOC "OUGHT"> ;<VOC "SHALL"> <VOC "SHE">
<VOC "SHOULD"> <VOC "THAT"> <VOC "THEY"> <VOC "WAS">
<VOC "WE"> <VOC "WERE"> <VOC "WILL"> <VOC "WOULD">
<VOC "YOU">>>
<CONSTANT P-QB-WORDS-2
<PLTABLE <VOC "NOT"> <VOC "NOT"> <VOC "NOT"> <VOC "NOT">
<VOC "NOT"> <VOC "NOT"> <VOC "IS"> <VOC "AM">
<VOC "NOT"> <VOC "IS"> ;<VOC "NOT"> ;<VOC "NOT">
;<VOC "NOT"> ;<VOC "NOT"> ;<VOC "NOT"> <VOC "IS">
<VOC "NOT"> <VOC "IS"> <VOC "ARE"> <VOC "NOT">
<VOC "ARE"> <VOC "NOT"> <VOC "NOT"> <VOC "NOT">
<VOC "ARE">>>
<CONSTANT P-QA-WORDS1
<PLTABLE <VOC "AREN"> <VOC "CAN"> <VOC "COULDN"> <VOC "DON">
<VOC "DOESN"> <VOC "DIDN"> <VOC "HE"> <VOC "I">
<VOC "ISN"> <VOC "IT"> ;<VOC "MAYN"> ;<VOC "MIGHTN">
;<VOC "MUSTN"> ;<VOC "OUGHTN"> ;<VOC "SHAN"> <VOC "SHE">
<VOC "SHOULDN"> <VOC "THAT"> <VOC "THEY"> <VOC "WASN">
<VOC "WE"> <VOC "WEREN"> <VOC "WON"> <VOC "WOULDN">
<VOC "YOU">>>
<CONSTANT P-QA-WORDS2
<PLTABLE <VOC "T"> <VOC "T"> <VOC "T"> <VOC "T">
<VOC "T"> <VOC "T"> <VOC "S"> <VOC "M">
<VOC "T"> <VOC "S"> ;<VOC "T"> ;<VOC "T">
;<VOC "T"> ;<VOC "T"> ;<VOC "T"> <VOC "S">
<VOC "T"> <VOC "S"> <VOC "RE"> <VOC "T">
<VOC "RE"> <VOC "T"> <VOC "T"> <VOC "T">
<VOC "RE">>>
<DEFAULT-DEFINITION SPECIAL-CONTRACTION?
<DEFINE SPECIAL-CONTRACTION? (PTR) <>>>
<DEFINE EXPAND-BE-CONTRACTIONS ("AUX" LEN PTR OPTR)
<SET LEN <GETB ,P-LEXV ,P-LEXWORDS>>
<SET PTR <REST-TO-SLOT ,P-LEXV LEXV-START>>
<SET OPTR .PTR>
<REPEAT (N WD SPWD (L .LEN))
<SET SPWD <>>
<COND (<DLESS? L 0>
<PUTB ,P-LEXV ,P-LEXWORDS .LEN>
<RETURN>)
(<AND <SET WD <ZGET .PTR 0>>
<EQUAL? <ZGET .PTR ,P-LEXELEN> ,W?APOSTROPHE>
<OR <AND <SET N <INTBL? .WD <ZREST ,P-QA-WORDS1 2>
<ZGET ,P-QA-WORDS1 0>>>
<EQUAL? <ZGET ,P-QA-WORDS2
<SET N </ <- .N ,P-QA-WORDS1> 2>>>
<ZGET .PTR <* 2 ,P-LEXELEN>>>>
<SET SPWD <SPECIAL-CONTRACTION? .PTR>>>>
<COPYT <ZREST .PTR <COND (<T? .SPWD>
<* 2 ,LEXV-ELEMENT-SIZE-BYTES>)
(T ,LEXV-ELEMENT-SIZE-BYTES)>>
.PTR
<* .L ,LEXV-ELEMENT-SIZE-BYTES>>
;"need to call INBUF-ADD-VOC for these words:"
<COND (<T? .SPWD>
<ZPUT .PTR 0 .SPWD>
<DEC L>
<DEC LEN>)
(T
<SET WD <ZGET ,P-QB-WORDS-1 .N>>
<ZPUT .PTR 0 .WD>
<SET WD <ZGET ,P-QB-WORDS-2 .N>>
<ZPUT .PTR ,P-LEXELEN .WD>)>
<DEC L>
<DEC LEN>)
(<AND <EQUAL? .WD ,W?APOSTROPHE> ;"e.g. Moses'"
<NOT <EQUAL? <ZGET .PTR ,P-LEXELEN> ,W?S>>
<NOT <EQUAL? .OPTR .PTR>>
<SET WD <ZBACK .PTR ,LEXV-ELEMENT-SIZE-BYTES>>
<EQUAL? <GETB ,P-INBUF <+ -1
<LEXV-WORD-LENGTH .WD>
<LEXV-WORD-OFFSET .WD>>>
!\s !\z>>
<MAKE-ROOM-FOR-TOKENS 1 ,P-LEXV
<+ ,P-LEXELEN </ <- .PTR ,P-LEXV> 2>>>
<ZPUT .PTR ,P-LEXELEN ,W?S>
<INC L>
<INC LEN>)
(T
<SET PTR <+ .PTR ,LEXV-ELEMENT-SIZE-BYTES>>)>>>)>
<DEFAULT-DEFINITION TELL-THE
<DEFINE TELL-THE (OBJ "AUX" TMP)
<COND (<EQUAL? .OBJ ,PLAYER>
<TELL "you">)
(T
<COND (<SET TMP <GET-OWNER .OBJ>>
<COND (<EQUAL? .TMP ,PLAYER>
<TELL "your ">)
(<NOT <EQUAL? .TMP .OBJ>>
<TELL-THE .TMP ;T>
<TELL "'s ">)>)
(<NOT <FSET? .OBJ ,NARTICLEBIT>>
<TELL "the ">)>
<TELL D .OBJ>)>>>
<DEFAULT-DEFINITION TELL-CTHE
<DEFINE TELL-CTHE (OBJ "AUX" TMP)
<COND (<EQUAL? .OBJ ,PLAYER>
<TELL "You">)
(T
<COND (<SET TMP <GET-OWNER .OBJ>>
<COND (<EQUAL? .TMP ,PLAYER>
<TELL "Your ">)
(<NOT <EQUAL? .TMP .OBJ>>
<TELL-CTHE .TMP ;T>
<TELL "'s ">)>)
(<NOT <FSET? .OBJ ,NARTICLEBIT>>
<TELL "The ">)>
<TELL D .OBJ>)>>>
<CONSTANT P-ADJ-CODE 1>
<CONSTANT P-COMMA-CODE 10>
<CONSTANT P-DIR-CODE 9>
<CONSTANT P-EOI-CODE 8>
<CONSTANT P-NOUN-CODE 2>
<CONSTANT P-PARTICLE-CODE 3>
<CONSTANT P-PREP-CODE 4>
<CONSTANT P-QUANT-CODE 5>
<CONSTANT P-QW1-CODE 6>
<CONSTANT P-VERB-CODE 7>
"Shared files should call this to check parts of speech:"
<DEFINE WORD-TYPE? ACT (WD TYP "OPT" TYP2
"AUX" GC (WCN <WORD-CLASSIFICATION-NUMBER .WD>))
<COND (<0? .WCN> ;"synonym?"
<SET WD <WORD-SEMANTIC-STUFF .WD>>
<SET WCN <WORD-CLASSIFICATION-NUMBER .WD>>)>
<COND (<AND <ASSIGNED? TYP2>
<WORD-TYPE? .WD .TYP2>>
<RETURN .WD>)>
<COND (<AND <EQUAL? .TYP ,P-COMMA-CODE>
<EQUAL? .WD ,W?COMMA ,W?AND>>
<RETURN .WD .ACT>)
(<EQUAL? .TYP ,P-ADJ-CODE>
<SET GC <GET-CLASSIFICATION ADJ>>)
(<EQUAL? .TYP ,P-DIR-CODE>
<SET GC <GET-CLASSIFICATION DIR>>)
(<EQUAL? .TYP ,P-EOI-CODE>
<SET GC <GET-CLASSIFICATION END-OF-INPUT>>)
(<EQUAL? .TYP ,P-NOUN-CODE>
<SET GC <GET-CLASSIFICATION NOUN>>)
(<EQUAL? .TYP ,P-PARTICLE-CODE>
<SET GC <GET-CLASSIFICATION PARTICLE>>)
(<EQUAL? .TYP ,P-PREP-CODE>
<SET GC <GET-CLASSIFICATION PREP>>)
(<EQUAL? .TYP ,P-QUANT-CODE>
<SET GC <GET-CLASSIFICATION QUANT>>)
(<EQUAL? .TYP ,P-QW1-CODE>
<SET GC %<COND (<LOOKUP "QWORD" ,SYMBOL-OBS>
<GET-CLASSIFICATION QWORD>)
(T 0)>>)
(<EQUAL? .TYP ,P-VERB-CODE>
<SET GC <GET-CLASSIFICATION VERB>>)>
<COND (
%<COND (<G? ,NUMBER-WORD-CLASSES:FIX 15>
<FORM AND <FORM ==? <FORM ANDB '.WCN *100000*>
<FORM ANDB '.GC *100000*>>
<FORM NOT
<FORM 0? <FORM ANDB '.WCN '.GC *77777*>>>>)
(T
<FORM NOT <FORM 0? <FORM ANDB '.WCN '.GC>>>)>
.WD)>>
<DEFINE IGNORE-FIRST-WORD (WD1 "OPT" (WD2 1) "AUX" NW)
<COND (<AND <EQUAL? <ZGET ,TLEXV 0> .WD1 .WD2> ;"Is this the first word ..."
<L? 1 ,P-LEN>
;<L? <- ,TLEXV ,P-LEXV> <- ,LEXV-LENGTH-BYTES <* 2 ,P-LEXELEN>>>
<SET NW <ZGET ,TLEXV ,P-LEXELEN>>
<COMPARE-WORD-TYPES <WORD-CLASSIFICATION-NUMBER .NW>
<GET-CLASSIFICATION VERB>> ;" followed by verb?">
<SETG TLEXV <ZREST ,TLEXV <* 2 ,P-LEXELEN>>> ;"If so, ignore it."
<SETG P-LEN <- ,P-LEN 1>>
T)>>
<COMPILATION-FLAG-DEFAULT P-TITLE-ABBRS <>>
<DEFAULT-DEFINITION TITLE-ABBR?
<DEFMAC TITLE-ABBR? ('WRD) <FORM EQUAL? .WRD ,W?MR ,W?MRS ,W?MS>>>
<IF-P-TITLE-ABBRS
<DEFINE FIX-TITLE-ABBRS ("AUX" LEN PTR)
<SET LEN <GETB ,P-LEXV ,P-LEXWORDS>>
<SET PTR <REST-TO-SLOT ,P-LEXV LEXV-START>>
<REPEAT (N (L .LEN))
<COND (<DLESS? L 0>
<RETURN>)
(<AND <TITLE-ABBR? <ZGET .PTR 0>>
<EQUAL? ,W?PERIOD <ZGET .PTR ,LEXV-ELEMENT-SIZE>>
<CAPITAL-NOUN? <ZGET .PTR <* 2 ,LEXV-ELEMENT-SIZE>>>>
<ZPUT .PTR ,LEXV-ELEMENT-SIZE ,W?NO.WORD>
;<COND (<CAPITAL-NOUN? <ZGET<BACK .PTR ,LEXV-ELEMENT-SIZE-BYTES>
0>>
;"JOHN D. FLATHEAD = JOHN FLATHEAD?"
<ZPUT .PTR 0 ,W?NO.WORD>)>)>
<SET PTR <+ .PTR ,LEXV-ELEMENT-SIZE-BYTES>>>>>
<DEFINE FIX-QUOTATIONS ()
<REPEAT (X (QFLAG <>)
(LEN <GETB ,P-LEXV ,P-LEXWORDS>)
(PTR <REST-TO-SLOT ,P-LEXV LEXV-START>))
<COND (<0? .LEN>
<RETURN>)
(<NOT <SET PTR <INTBL? ,W?QUOTE .PTR .LEN *204*>>>
<RETURN>)
(T
<COND (<NOT .QFLAG>
<SET QFLAG T>
<SET X <+ ,LEXV-ELEMENT-SIZE </ <- .PTR ,P-LEXV> 2>>>
<MAKE-ROOM-FOR-TOKENS 1 ,P-LEXV .X>
<ZPUT ,P-LEXV .X ,W?NO.WORD>)
(T
<SET QFLAG <>>)>
<SET PTR <+ .PTR ,LEXV-ELEMENT-SIZE-BYTES>>
<SET X </ <- .PTR ,P-LEXV> ,LEXV-ELEMENT-SIZE-BYTES>>
<SET LEN <- <GETB ,P-LEXV ,P-LEXWORDS> .X>>)>>>
<COMPILATION-FLAG-DEFAULT P-PS-ADV T>
<COMPILATION-FLAG-DEFAULT P-ZORK0 <>>
<GLOBAL P-DIRECTION:NUMBER 0>
<DEFINE PARSER PARSER ("AUX" OWINNER LEN N)
<COND (T ;<F? ,P-OFLAG>
<IF-P-DEBUGGING-PARSER
<COND (<T? ,P-DBUG>
<PRINTI "[Reset of PMEM: ">
<PRINTN ,PMEM-WORDS-USED>
<PRINTI " words used.]|">)>>
<PMEM-RESET>)>
<SETG ERROR-PRIORITY 255>
<SETG ERROR-STRING <>>
<SET OWINNER ,WINNER>
<COND (<NOT <F? ,M-PTR>>
<COPYT ,M-LEXV ,P-LEXV ,LEXV-LENGTH-BYTES>
<COPYT ,M-INBUF ,P-INBUF <+ 1 ,INBUF-LENGTH>>
<SETG P-LEN ,M-LEN>
<COND (<AND <NOT <0? ,VERBOSITY>> <EQUAL? ,PLAYER ,WINNER>>
<CRLF>)>
<SETG TLEXV ,M-PTR>
<SETG M-PTR <>>
<SETG P-CONT <>>)
(<G? ,P-CONT 0>
<SETG TLEXV ,P-CONT>
<COND (<AND <NOT <0? ,VERBOSITY>> <EQUAL? ,PLAYER ,WINNER>>
<CRLF>)>
<SETG P-CONT <>>)
(T
<SETG WINNER ,PLAYER>
<COND (<AND <ZERO? ,P-OFLAG>
<ZERO? <ZGET ,OOPS-TABLE ,O-PTR>>>
<ZPUT ,OOPS-TABLE ,O-END <>>)>
<COND (<IN? <LOC ,WINNER> ,ROOMS>
;<NOT <FSET? <LOC ,WINNER> ,VEHBIT>>
<SETG HERE <LOC ,WINNER>>)>
<COND (<OR <ZERO? ,LIT>
<AND <NOT <EQUAL? ,HERE ,LIT>>
<NOT <VISIBLE? ,LIT>>>>
<SETG LIT <LIT? ;,HERE>>)>
<FCLEAR ,IT ,TOUCHBIT> ;"to prevent pronouns w/o referents"
<FCLEAR ,HER ,TOUCHBIT>
<FCLEAR ,HIM ,TOUCHBIT>
<COND (<BTST <LOWCORE FLAGS> 4>
<V-$REFRESH>)>
<COND (<NOT <0? ,VERBOSITY>> <CRLF>)>
<COND (T ;<OR <CHECK-EXTENDED? XZIP>
<CHECK-EXTENDED? YZIP>>
<UPDATE-STATUS-LINE>)>
<TELL ">">
<READ-INPUT>
<FIX-QUOTATIONS>
<IFFLAG (<AND P-BE-VERB P-APOSTROPHE-BREAKS-WORDS>
<EXPAND-BE-CONTRACTIONS>)>
<IFFLAG (P-TITLE-ABBRS
<FIX-TITLE-ABBRS>)>
<SETG P-LEN <GETB ,P-LEXV ,P-LEXWORDS>>
<SETG TLEXV <REST-TO-SLOT ,P-LEXV LEXV-START>>)>
<COND (<EQUAL? <ZGET ,TLEXV 0>
,W?PERIOD ,W?THEN> ;"Is THEN first input word?"
<SETG TLEXV <ZREST ,TLEXV <* 2 ,P-LEXELEN>>>;"If so, ignore it."
<SETG P-LEN <- ,P-LEN 1>>)>
<IGNORE-FIRST-WORD ,W?YOU>
<IGNORE-FIRST-WORD ,W?GO ,W?TO>
<COND (<0? ,P-LEN>
<BEG-PARDON>
<RETURN <> .PARSER>)>
;<IF-UNDO
<COND (<AND <EQUAL? <ZGET ,TLEXV 0> ,W?UNDO>
<EQUAL? ,P-LEN 1>
<V-UNDO>>
<RETURN <> .PARSER>)
(<T? <ZGET ,TLEXV 0>> ;"not unknown word?"
<SETG P-CAN-UNDO <ISAVE>>
<COND (<EQUAL? ,P-CAN-UNDO 2>
<COND (<EQUAL? <ZGET ,P-LEXV ,P-LEXSTART>,W?SAVE>
<CANT-UNDO>)
(T
<V-$REFRESH>
;<TELL "[Undone.]|">)>
<AGAIN>)>)>>
<COND ;"At this point, handle naked directions for speed."
(<AND <SET LEN <WORD-TYPE? <ZGET ,TLEXV 0> ,P-DIR-CODE>>
<OR <EQUAL? ,P-LEN 1>
<G=? <- ,TLEXV ,P-LEXV>
<- ,LEXV-LENGTH-BYTES <* 2 ,P-LEXELEN>>>
<WORD-TYPE? <ZGET ,TLEXV ,P-LEXELEN>
,P-EOI-CODE ,P-COMMA-CODE>>>
<CLEAR-PSTACK ,STATE-STACK>
<CLEAR-PSTACK ,DATA-STACK>
<PUSH-PSTACK ,DATA-STACK .LEN>
<RED-SD 1>
<SETG P-CONT <>>
<SETG P-OFLAG 0>
<SETG P-WORDS-AGAIN 1>
<ZPUT ,OOPS-TABLE ,O-END <>>
;<ZPUT ,OOPS-TABLE ,O-AGAIN <ZGET ,OOPS-TABLE ,O-START>>
<SETG M-PTR <>>
<PUTB ,P-LEXV ,P-LEXWORDS ,P-LEN>
<COPYT ,P-LEXV ,G-LEXV ,LEXV-LENGTH-BYTES>
<COPYT ,P-INBUF ,G-INBUF <+ 1 ,INBUF-LENGTH>>
<PARSE-SUBJ ,PARSE-RESULT 0>
<COND (<AND <L? 0 <SETG P-LEN <- ,P-LEN 1>>>
<SET LEN <ZGET <SETG TLEXV
<ZREST,TLEXV ,LEXV-ELEMENT-SIZE-BYTES>>
0>>
<COMPARE-WORD-TYPES <WORD-CLASSIFICATION-NUMBER .LEN>
<GET-CLASSIFICATION END-OF-INPUT>>>
<SETG P-WORDS-AGAIN ,P-WORD-NUMBER>
<COND (<NOT <L? <SETG P-LEN <- ,P-LEN 1>> 1>>
<SETG P-CONT <ZREST ,TLEXV
,LEXV-ELEMENT-SIZE-BYTES>>)
;(T <SETG P-CONT <>>)>)>
<RETURN T .PARSER>)
(<==? <ZGET ,TLEXV 0> ,W?OOPS ,W?O>
<PROG ((PTR ,P-LEXSTART) VAL LEN CNT)
<COND (<EQUAL? <ZGET ,TLEXV ,P-LEXELEN:FIX>
,W?PERIOD ,W?COMMA>
<SET PTR <+ .PTR ,P-LEXELEN:FIX>>
<SETG P-LEN <- ,P-LEN 1>>)>
<COND (<L=? ,P-LEN 1>
<NAKED-OOPS>
<RETURN <> .PARSER>)
(<NOT <EQUAL? ,HERE <META-LOC .OWINNER>>>
<NOT-HERE .OWINNER>
<RETURN <> .PARSER>)
(<SET VAL <ZGET ,OOPS-TABLE ,O-PTR>>
<REPLACE-ONE-TOKEN <- ,P-LEN 1> ,P-LEXV .PTR ,G-LEXV .VAL>
<SETG WINNER .OWINNER> ;"Fixes OOPS w/chars"
<COPY-INPUT T>)
(T
<ZPUT ,OOPS-TABLE ,O-END <>>
<CANT-OOPS>
<RETURN <> .PARSER>)>>)
(<AND <ZERO? ,P-OFLAG>
<L? ,P-CONT 1>>
<ZPUT ,OOPS-TABLE ,O-END <>>)>
<SETG P-CONT <>>
<COND (<EQUAL? <ZGET ,TLEXV 0> ,W?AGAIN ,W?G>
<COND (<OR <T? ,P-OFLAG>
<F? ,P-WON>
<0? <GETB ,G-INBUF 2>>>
<CANT-AGAIN>
<RETURN <> .PARSER>)
(<AND <G? ,P-LEN 1>
<L? <- ,TLEXV ,P-LEXV> ;"for ZIP20 bug"
<- ,LEXV-LENGTH-BYTES <* 2 ,P-LEXELEN>>>>
<SET N <ZGET ,TLEXV ,P-LEXELEN>>
<COND (<EQUAL? .N ,W?PERIOD ,W?COMMA ,W?THEN ,W?AND>
<SETG TLEXV <ZREST ,TLEXV <* 2 ,P-LEXELEN>>>
<SETG P-LEN <- ,P-LEN 1>>)
(T
<DONT-UNDERSTAND>
<RETURN <> .PARSER>)>)>
<SETG P-LEN <- ,P-LEN 1>>
<SETG TLEXV <ZREST ,TLEXV <* ,P-LEXELEN:FIX 2>>>
<COND (<G? ,P-LEN 0>
<COPYT ,P-LEXV ,M-LEXV ,LEXV-LENGTH-BYTES>
<COPYT ,P-INBUF ,M-INBUF <+ 1 ,INBUF-LENGTH>>
<SETG M-LEN ,P-LEN>
<SETG M-PTR ,TLEXV>
<SETG P-CONT ,M-PTR>)
(T
<SETG M-PTR <>>)>
<COND (<NOT <EQUAL? ,HERE <META-LOC .OWINNER>>>
<NOT-HERE .OWINNER>
<RETURN <> .PARSER>)>
<SETG WINNER .OWINNER>
<COPYT ,G-INBUF ,P-INBUF <+ 1 ,INBUF-LENGTH>>
<COPYT ,G-LEXV ,P-LEXV ,LEXV-LENGTH-BYTES>
<SETG P-LEN ,P-WORDS-AGAIN>
<SETG TLEXV <ZGET ,OOPS-TABLE ,O-START ;,O-AGAIN>>)
(T
<SETG M-PTR <>>
<PUTB ,P-LEXV ,P-LEXWORDS ,P-LEN>
<COPYT ,P-LEXV ,G-LEXV ,LEXV-LENGTH-BYTES>
<COPYT ,P-INBUF ,G-INBUF <+ 1 ,INBUF-LENGTH>>
<ZPUT ,OOPS-TABLE ,O-START ,TLEXV>
<ZPUT ,OOPS-TABLE ,O-LENGTH ,P-LEN>
;<ZPUT ,OOPS-TABLE ,O-AGAIN ,TLEXV>
<COND (<ZERO? <ZGET ,OOPS-TABLE ,O-END>>
<SET LEN <* <* 2 ,P-LEXELEN:FIX>
<GETB ,P-LEXV ,P-LEXWORDS>>>
<ZPUT ,OOPS-TABLE ,O-END
<+ <GETB ,TLEXV <SET LEN <- .LEN 1>>>
<GETB ,TLEXV <SET LEN <- .LEN 1>>>>>)>)>
<SETG P-WALK-DIR <>>
<PROG ((PV <PARSE-IT <>>))
<COND
(<ZERO? .PV>
<SET PV <PRINT-PARSER-FAILURE>>
<AGAIN>)
(<1? .PV>
<RETURN <> .PARSER>)
(T
<ZPUT ,OOPS-TABLE ,O-PTR <>>
<COND (<NOT <GAME-VERB?>>
<SETG P-OFLAG 0>)>
<IF-P-PS-ADV
<COND (<AND <EQUAL? <SET LEN <PARSE-ADV .PV>> ,W?TWICE ,W?THRICE>
<SET N <INTBL? .LEN
<ZGET ,OOPS-TABLE ,O-START>
,P-WORDS-AGAIN
*204*>>>
<CHANGE-LEXV .N ,W?ONCE> ;"to avoid repeating"
<DO-IT-AGAIN <COND (<EQUAL? .LEN ,W?THRICE> 2) (T 1)>>
<SET PV <PARSE-IT <>>>
<AGAIN>)>
<IF-P-ZORK0
<COND (<EQUAL? .LEN ,W?DON\'T>
<COND (<EQUAL? ,WINNER ,EXECUTIONER>
<TELL
"\"Tell me what you want me to do, not what you don't.\"" CR>)
(T <TELL "[Not done.]" CR>)>
<RETURN <> .PARSER>)>>>
<COND (<T? <ZGET ,GWIM-MSG 1>>
<TELL-GWIM-MSG>
<ZPUT ,GWIM-MSG 1 0>)>
<RETURN T .PARSER>)>>>
<CONSTANT GWIM-MSG <TABLE 0 ;"prep" 0 ;"object">>
<DEFAULT-DEFINITION TELL-GWIM-MSG
<DEFINE TELL-GWIM-MSG ("AUX" WD VB)
<TELL !\[>
<COND (<T? <SET WD <ZGET ,GWIM-MSG 0>>>
<PRINT-VOCAB-WORD .WD>
<TELL !\ >
<SET VB <PARSE-VERB ,PARSER-RESULT>>
<COND (<EQUAL? .VB ,W?SIT ,W?LIE>
<COND (<EQUAL? .WD ,W?DOWN>
<TELL "on ">)>)
(<EQUAL? .VB ,W?GET>
<COND (<EQUAL? .WD ,W?OUT>
<TELL "of ">)>)>)>
<TELL-THE <ZGET ,GWIM-MSG 1>>
<TELL "]" CR>>>
;<DEFAULT-DEFINITION CANT-UNDO
<IF-UNDO
<DEFINE CANT-UNDO ()
<TELL "[I can't undo that.]" CR>>>>
"Take the input list, and return a list of possible parses"
<IFFLAG (P-DEBUGGING-PARSER
<GLOBAL SPLITS:NUMBER 0>
<DEFINE P-P (X)
<COND (<PMEM? .X>
<COND (<PMEM-TYPE? .X ADJS> ;1
<PRINTI "#ADJS[">
<ADJS-PRINT .X>
<PRINTI "]">)
(<PMEM-TYPE? .X NP> ;2
<PRINTI "#NP[">
<NP-PRINT .X>
<PRINTI "]">)
(<PMEM-TYPE? .X NPP> ;3
<PRINTI "#NPP[">
<REPEAT ()
<COND (<NPP-NOUN .X>
<P-P <NPP-NOUN .X>>
<PRINTI " ">)>
<COND (<NPP-NOUN-PHRASE .X>
<P-P <NPP-NOUN-PHRASE .X>>
<PRINTI " ">)>
<COND ;(T
<P-P <NPP-NEXT .X>>
;<PRINTI " ">)
(<NOT <SET X <NPP-NEXT .X>>>
<RETURN>)>>
<PRINTI "]">)
(<PMEM-TYPE? .X NOUN-PHRASE> ;4
<PRINTI "#NOUN-PHRASE[">
<NP-PRINT .X>
<PRINTI "]">)
(<OR <PMEM-TYPE? .X PP> ;5
<PMEM-TYPE? .X LOCATION> ;6>
<PRINTI "#PP[">
<PRINTI "W?">
<PRINTB <PP-PREP .X>>
<PRINTI " ">
<P-P <PP-NOUN .X>>
<PRINTI "]">)
;(<PMEM-TYPE? .X OBJLIST> ;7
<PRINTI "#OBJLIST[">
<>
<PRINTI "]">)
(T <PRINTI "#PMEM[]">)>)
(<EQUAL? .X ,PARSE-RESULT>
<PRINTI "RESULT">)
(<OR <AND ;<L? 0 ,VOCAB>
<L? ,VOCAB ,PRSTBL>
<AND <L? ,VOCAB .X>
<L? .X ,PRSTBL>>>
<AND <L? 0 ,VOCAB>
<L? ,PRSTBL 0>
<OR <L? ,VOCAB .X>
<L? .X ,PRSTBL>>>>
<PRINTI "W?">
<PRINTB .X>)
(T <PRINTN .X>)>>)
(T
<GDECL (SPLITS) FIX>)>
<CONSTANT PARSE-RESULT <MAKE-PARSE-RESULT>>
<GLOBAL P-WORD-NUMBER:NUMBER ;BYTE 0>
<GLOBAL P-WORDS-AGAIN:NUMBER ;BYTE 0>
<GLOBAL P-OLEN:NUMBER 0>
<DEFINE PARSE-IT PI ("OPT" (V:<OR FALSE PARSE-RESULT> <>)
"AUX" RES:FIX (NUM 0) (SAV-LEXV ,TLEXV))
<IFFLAG (P-DEBUGGING-PARSER
<SETG SPLITS 0>)
(T
<DEBUG20 <SETG SPLITS 0>>)>
<PSTACK-PTR ,SPLIT-STACK 0>
<SETG ERROR-PRIORITY 255>
<ZPUT ,ERROR-ARGS 1 0>
<SETG P-OLEN ,P-LEN>
<SETG OTLEXV ,TLEXV>
<REPEAT ()
<SET NUM <+ 1 .NUM>>
<BE-PATIENT .NUM>
<CLEAR-PSTACK ,STATE-STACK>
<PUSH-PSTACK ,STATE-STACK 1>
<CLEAR-PSTACK ,DATA-STACK>
<IF-P-DEBUGGING-PARSER
<COND (<T? ,P-DBUG>
<PRINTI "[Reset of PMEM: ">
<PRINTN ,PMEM-WORDS-USED>
<PRINTI " words used.]|">)>>
<PMEM-RESET <>>
<SETG P-WORD-NUMBER 0>
<SETG TLEXV .SAV-LEXV>
<SETG P-LEN ,P-OLEN>
<ZPUT ,GWIM-MSG 0 0>
<ZPUT ,GWIM-MSG 1 0>
;<ZPUT ,ERROR-ARGS 1 0>
<MAKE-PARSE-RESULT 'PARSE-RESULT ,PARSE-RESULT
'PARSE-VERB <COND (.V <PARSE-VERB .V>)>
'PARSE-OBJ1 <COND (.V <PARSE-OBJ1 .V>)>
'PARSE-LOC <COND (.V <PARSE-LOC .V>)>
'PARSE-QW <COND (.V <PARSE-QW .V>)>
'PARSE-ADJ <COND (.V <PARSE-ADJ .V>)>
'PARSE-SUBJ <COND (.V <PARSE-SUBJ .V>)>
'PARSE-QUERY <COND (.V <PARSE-QUERY .V>)>>
<SET RES <PARSE-SENTENCE ,PARSE-RESULT>>
<COND (<==? .RES ,PARSER-RESULT-AGAIN>
<PSTACK-PTR ,SPLIT-STACK 0>
<SETG ERROR-PRIORITY 255>
<SETG P-OLEN ,P-LEN>
<SET SAV-LEXV ,TLEXV ;<REST-TO-SLOT ,P-LEXV LEXV-START>>
<AGAIN>)
(<NOT <L? .RES ,PARSER-RESULT-WON>>
<RETURN>)
(<OR <0? <PSTACK-PTR ,SPLIT-STACK>>
<==? .RES ,PARSER-RESULT-DEAD>>
;"DEAD means unknown word or something else
that couldn't be recovered by trying some other path"
<RETURN>)>
;"In case of partial success, anything saved has to be in orphan stuff"
<REPEAT (TMP TV:TABLE T2)
<SET T2 <PSTACK-PTR ,SPLIT-STACK>>
<COND (<0? <ZGET ,SPLIT-STACK <- .T2 1>>>
<COND (<OR <NOT <SET TMP <ZGET ,SPLIT-STACK .T2>>>
<IF-SHORT <0? <ZGET .TMP:TABLE 0>:FIX>
<AND <0? <ZGET .TMP:TABLE 0>:FIX>
<0? <ZGET .TMP:TABLE 1>:FIX>>>
<IF-SHORT <0? <ZGET <SET TV <ZREST .TMP:TABLE 4>> 0>>
<AND <0? <ZGET <SET TV <ZREST .TMP 6>> 0>>
<0? <ZGET .TV 1>:FIX>>>>
<PSTACK-PTR ,SPLIT-STACK <- .T2 2>>)
(T
<ZPUT ,SPLIT-STACK .T2 .TV>
<RETURN>)>)
(<==? <ZGET ,SPLIT-STACK .T2>
<ZGET ,SPLIT-STACK <- .T2 1>>>
;"Through with this case"
<PSTACK-PTR ,SPLIT-STACK <- .T2 2>>)
(T
<ZPUT ,SPLIT-STACK .T2 <+ 1 <ZGET ,SPLIT-STACK .T2>>>
<RETURN>)>
<COND (<0? <PSTACK-PTR ,SPLIT-STACK>>
<RETURN>)>>
<COND (<0? <PSTACK-PTR ,SPLIT-STACK>>
<RETURN>)>
<IF-P-DEBUGGING-PARSER
<COND (<T? ,P-DBUG>