-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathparser.zap
1600 lines (1513 loc) · 33.3 KB
/
parser.zap
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
.FUNCT PARSER,PTR=P-LEXSTART,WRD,VAL=0,VERB=0,OF-FLAG=0,OWINNER,OMERGED,LEN,DIR=0,NW=0,LW=0,CNT=-1,?TMP2,?TMP1
?PRG1: IGRTR? 'CNT,P-ITBLLEN /?REP2
ZERO? P-OFLAG \?CND6
GET P-ITBL,CNT
PUT P-OTBL,CNT,STACK
?CND6: PUT P-ITBL,CNT,0
JUMP ?PRG1
?REP2: SET 'OWINNER,WINNER
SET 'OMERGED,P-MERGED
SET 'P-ADVERB,FALSE-VALUE
SET 'P-MERGED,FALSE-VALUE
SET 'P-END-ON-PREP,FALSE-VALUE
PUT P-PRSO,P-MATCHLEN,0
PUT P-PRSI,P-MATCHLEN,0
PUT P-BUTS,P-MATCHLEN,0
ZERO? QUOTE-FLAG \?CND8
EQUAL? WINNER,ADVENTURER /?CND8
SET 'WINNER,ADVENTURER
CALL META-LOC,ADVENTURER >HERE
CALL LIT?,HERE >LIT
?CND8: ZERO? RESERVE-PTR /?CCL14
SET 'PTR,RESERVE-PTR
CALL STUFF,RESERVE-LEXV,P-LEXV
GRTR? VERBOSITY,0 \?CND15
EQUAL? ADVENTURER,WINNER \?CND15
CRLF
?CND15: SET 'RESERVE-PTR,FALSE-VALUE
SET 'P-CONT,FALSE-VALUE
JUMP ?CND12
?CCL14: ZERO? P-CONT /?CCL20
SET 'PTR,P-CONT
GRTR? VERBOSITY,0 \?CND21
EQUAL? ADVENTURER,WINNER \?CND21
EQUAL? PRSA,V?SAY /?CND21
CRLF
?CND21: SET 'P-CONT,FALSE-VALUE
JUMP ?CND12
?CCL20: SET 'WINNER,ADVENTURER
SET 'QUOTE-FLAG,FALSE-VALUE
LOC WINNER
FSET? STACK,VEHBIT /?CND26
LOC WINNER >HERE
?CND26: CALL LIT?,HERE >LIT
GRTR? VERBOSITY,0 \?PRG30
CRLF
?PRG30: PRINTC 62
READ P-INBUF,P-LEXV
?CND12: GETB P-LEXV,P-LEXWORDS >P-LEN
ZERO? P-LEN \?CND32
PRINTI "I beg your pardon?"
CRLF
RFALSE
?CND32: GET P-LEXV,PTR >WRD
EQUAL? WRD,W?OOPS \?CCL38
ADD PTR,P-LEXELEN
GET P-LEXV,STACK
EQUAL? STACK,W?PERIOD,W?COMMA \?CND39
ADD PTR,P-LEXELEN >PTR
DEC 'P-LEN
?CND39: GRTR? P-LEN,1 /?CCL43
PRINTI "I can't help your clumsiness."
CRLF
RFALSE
?CCL43: GET OOPS-TABLE,O-PTR
ZERO? STACK /?CCL47
GRTR? P-LEN,2 \?CCL50
ADD PTR,P-LEXELEN
GET P-LEXV,STACK
EQUAL? STACK,W?QUOTE \?CCL50
PRINTI "Sorry, you can't correct mistakes in quoted text."
CRLF
RFALSE
?CCL50: GRTR? P-LEN,2 \?CND48
PRINTI "Warning: only the first word after OOPS is used."
CRLF
?CND48: GET OOPS-TABLE,O-PTR >?TMP1
ADD PTR,P-LEXELEN
GET P-LEXV,STACK
PUT AGAIN-LEXV,?TMP1,STACK
SET 'WINNER,OWINNER
MUL PTR,P-LEXELEN
ADD STACK,6
GETB P-LEXV,STACK >?TMP2
MUL PTR,P-LEXELEN
ADD STACK,7
GETB P-LEXV,STACK >?TMP1
GET OOPS-TABLE,O-PTR
MUL STACK,P-LEXELEN
ADD STACK,3
CALL INBUF-ADD,?TMP2,?TMP1,STACK
CALL STUFF,AGAIN-LEXV,P-LEXV
GETB P-LEXV,P-LEXWORDS >P-LEN
GET OOPS-TABLE,O-START >PTR
CALL INBUF-STUFF,OOPS-INBUF,P-INBUF
JUMP ?CND36
?CCL47: PUT OOPS-TABLE,O-END,FALSE-VALUE
PRINTI "There was no word to replace!"
CRLF
RFALSE
?CCL38: EQUAL? WRD,W?AGAIN,W?G /?CND60
SET 'P-NUMBER,0
?CND60: PUT OOPS-TABLE,O-END,FALSE-VALUE
?CND36: GET P-LEXV,PTR
EQUAL? STACK,W?AGAIN,W?G \?CCL64
GETB OOPS-INBUF,1
ZERO? STACK \?CCL67
PRINTI "Beg pardon?"
CRLF
RFALSE
?CCL67: ZERO? P-OFLAG /?CCL71
PRINTI "It's difficult to repeat fragments."
CRLF
RFALSE
?CCL71: ZERO? P-WON \?CCL75
PRINTI "That would just repeat a mistake."
CRLF
RFALSE
?CCL75: GRTR? P-LEN,1 \?CCL79
ADD PTR,P-LEXELEN
GET P-LEXV,STACK
EQUAL? STACK,W?PERIOD,W?COMMA,W?THEN /?CTR81
ADD PTR,P-LEXELEN
GET P-LEXV,STACK
EQUAL? STACK,W?AND \?PRG85
?CTR81: ADD PTR,4 >PTR
GETB P-LEXV,P-LEXWORDS
SUB STACK,2
PUTB P-LEXV,P-LEXWORDS,STACK
JUMP ?CND65
?PRG85: PRINTI "I couldn't understand that sentence."
CRLF
RFALSE
?CCL79: ADD PTR,P-LEXELEN >PTR
GETB P-LEXV,P-LEXWORDS
SUB STACK,1
PUTB P-LEXV,P-LEXWORDS,STACK
?CND65: GETB P-LEXV,P-LEXWORDS
GRTR? STACK,0 \?CCL89
CALL STUFF,P-LEXV,RESERVE-LEXV
SET 'RESERVE-PTR,PTR
JUMP ?CND87
?CCL89: SET 'RESERVE-PTR,FALSE-VALUE
?CND87: SET 'WINNER,OWINNER
SET 'P-MERGED,OMERGED
CALL INBUF-STUFF,OOPS-INBUF,P-INBUF
CALL STUFF,AGAIN-LEXV,P-LEXV
SET 'CNT,-1
SET 'DIR,AGAIN-DIR
?PRG90: IGRTR? 'CNT,P-ITBLLEN /?CND62
GET P-OTBL,CNT
PUT P-ITBL,CNT,STACK
JUMP ?PRG90
?CCL64: CALL STUFF,P-LEXV,AGAIN-LEXV
CALL INBUF-STUFF,P-INBUF,OOPS-INBUF
PUT OOPS-TABLE,O-START,PTR
MUL 4,P-LEN
PUT OOPS-TABLE,O-LENGTH,STACK
GETB P-LEXV,P-LEXWORDS
MUL P-LEXELEN,STACK
ADD PTR,STACK
MUL 2,STACK >LEN
SUB LEN,1
GETB P-LEXV,STACK >?TMP1
SUB LEN,2
GETB P-LEXV,STACK
ADD ?TMP1,STACK
PUT OOPS-TABLE,O-END,STACK
SET 'RESERVE-PTR,FALSE-VALUE
SET 'LEN,P-LEN
SET 'P-DIR,FALSE-VALUE
SET 'P-NCN,0
SET 'P-GETFLAGS,0
?PRG95: DLESS? 'P-LEN,0 \?CCL99
SET 'QUOTE-FLAG,FALSE-VALUE
JUMP ?CND62
?CCL99: GET P-LEXV,PTR >WRD
ZERO? WRD \?CTR100
CALL NUMBER?,PTR >WRD
ZERO? WRD /?CCL101
?CTR100: ZERO? P-LEN \?CCL106
SET 'NW,0
JUMP ?CND104
?CCL106: ADD PTR,P-LEXELEN
GET P-LEXV,STACK >NW
?CND104: EQUAL? WRD,W?TO \?CCL109
EQUAL? VERB,ACT?TELL \?CCL109
SET 'WRD,W?QUOTE
JUMP ?CND107
?CCL109: EQUAL? WRD,W?THEN \?CND107
GRTR? P-LEN,0 \?CND107
ZERO? VERB \?CND107
ZERO? QUOTE-FLAG \?CND107
EQUAL? LW,0,W?PERIOD \?CCL119
SET 'WRD,W?THE
JUMP ?CND107
?CCL119: PUT P-ITBL,P-VERB,ACT?TELL
PUT P-ITBL,P-VERBN,0
SET 'WRD,W?QUOTE
?CND107: EQUAL? WRD,W?THEN,W?PERIOD,W?QUOTE \?CCL122
EQUAL? WRD,W?QUOTE \?CND123
ZERO? QUOTE-FLAG /?CCL127
SET 'QUOTE-FLAG,FALSE-VALUE
JUMP ?CND123
?CCL127: SET 'QUOTE-FLAG,TRUE-VALUE
?CND123: ZERO? P-LEN /?PEN128
ADD PTR,P-LEXELEN >P-CONT
?PEN128: PUTB P-LEXV,P-LEXWORDS,P-LEN
JUMP ?CND62
?CCL122: CALL WT?,WRD,16,3 >VAL
ZERO? VAL /?CCL131
EQUAL? VERB,FALSE-VALUE,ACT?WALK \?CCL131
EQUAL? LEN,1 /?CTR130
EQUAL? LEN,2 \?PRD137
EQUAL? VERB,ACT?WALK /?CTR130
?PRD137: EQUAL? NW,W?THEN,W?PERIOD,W?QUOTE \?PRD140
LESS? LEN,2 \?CTR130
?PRD140: ZERO? QUOTE-FLAG /?PRD143
EQUAL? LEN,2 \?PRD143
EQUAL? NW,W?QUOTE /?CTR130
?PRD143: GRTR? LEN,2 \?CCL131
EQUAL? NW,W?COMMA,W?AND \?CCL131
?CTR130: SET 'DIR,VAL
EQUAL? NW,W?COMMA,W?AND \?CND149
ADD PTR,P-LEXELEN
PUT P-LEXV,STACK,W?THEN
?CND149: GRTR? LEN,2 /?CND97
SET 'QUOTE-FLAG,FALSE-VALUE
JUMP ?CND62
?CCL131: CALL WT?,WRD,64,1 >VAL
ZERO? VAL /?CCL154
ZERO? VERB \?CCL154
SET 'VERB,VAL
PUT P-ITBL,P-VERB,VAL
PUT P-ITBL,P-VERBN,P-VTBL
PUT P-VTBL,0,WRD
MUL PTR,2
ADD STACK,2 >CNT
GETB P-LEXV,CNT
PUTB P-VTBL,2,STACK
ADD CNT,1
GETB P-LEXV,STACK
PUTB P-VTBL,3,STACK
JUMP ?CND97
?CCL154: CALL WT?,WRD,8,0 >VAL
ZERO? VAL \?CTR157
EQUAL? WRD,W?ALL,W?ONE /?CTR157
CALL WT?,WRD,32
ZERO? STACK \?CTR157
CALL WT?,WRD,128
ZERO? STACK /?CCL158
?CTR157: GRTR? P-LEN,1 \?CCL165
EQUAL? NW,W?OF \?CCL165
ZERO? VAL \?CCL165
EQUAL? WRD,W?ALL,W?ONE,W?A /?CCL165
SET 'OF-FLAG,TRUE-VALUE
JUMP ?CND97
?CCL165: ZERO? VAL /?CCL171
ZERO? P-LEN /?CTR170
EQUAL? NW,W?THEN,W?PERIOD \?CCL171
?CTR170: SET 'P-END-ON-PREP,TRUE-VALUE
LESS? P-NCN,2 \?CND97
PUT P-ITBL,P-PREP1,VAL
PUT P-ITBL,P-PREP1N,WRD
JUMP ?CND97
?CCL171: EQUAL? P-NCN,2 \?CCL179
PRINTI "There were too many nouns in that sentence."
CRLF
RFALSE
?CCL179: INC 'P-NCN
SET 'P-ACT,VERB
CALL CLAUSE,PTR,VAL,WRD >PTR
ZERO? PTR /FALSE
LESS? PTR,0 \?CND97
SET 'QUOTE-FLAG,FALSE-VALUE
?CND62: PUT OOPS-TABLE,O-PTR,FALSE-VALUE
ZERO? DIR /?CCL203
SET 'PRSA,V?WALK
SET 'PRSO,DIR
SET 'P-OFLAG,FALSE-VALUE
SET 'P-WALK-DIR,DIR
SET 'AGAIN-DIR,DIR
RETURN AGAIN-DIR
?CCL158: EQUAL? WRD,W?OF \?CCL187
ZERO? OF-FLAG /?CTR189
EQUAL? NW,W?PERIOD,W?THEN \?CCL190
?CTR189: CALL CANT-USE,PTR
RFALSE
?CCL190: SET 'OF-FLAG,FALSE-VALUE
?CND97: SET 'LW,WRD
ADD PTR,P-LEXELEN >PTR
JUMP ?PRG95
?CCL187: CALL WT?,WRD,4
ZERO? STACK \?CND97
EQUAL? VERB,ACT?TELL \?CCL195
CALL WT?,WRD,64,1
ZERO? STACK /?CCL195
EQUAL? WINNER,ADVENTURER \?CCL195
PRINTI "Please consult your manual for the correct way to talk to other people or creatures."
CRLF
RFALSE
?CCL195: CALL CANT-USE,PTR
RFALSE
?CCL101: CALL UNKNOWN-WORD,PTR
RFALSE
?CCL203: ZERO? P-OFLAG /?CND204
CALL ORPHAN-MERGE
?CND204: SET 'P-WALK-DIR,FALSE-VALUE
SET 'AGAIN-DIR,FALSE-VALUE
CALL SYNTAX-CHECK
ZERO? STACK /FALSE
CALL SNARF-OBJECTS
ZERO? STACK /FALSE
CALL MANY-CHECK
ZERO? STACK /FALSE
CALL TAKE-CHECK
ZERO? STACK \TRUE
RFALSE
.FUNCT STUFF,SRC,DEST,MAX=29,PTR=P-LEXSTART,CTR=1,BPTR
GETB SRC,0
PUTB DEST,0,STACK
GETB SRC,1
PUTB DEST,1,STACK
?PRG1: GET SRC,PTR
PUT DEST,PTR,STACK
MUL PTR,2
ADD STACK,2 >BPTR
GETB SRC,BPTR
PUTB DEST,BPTR,STACK
MUL PTR,2
ADD STACK,3 >BPTR
GETB SRC,BPTR
PUTB DEST,BPTR,STACK
ADD PTR,P-LEXELEN >PTR
IGRTR? 'CTR,MAX \?PRG1
RTRUE
.FUNCT INBUF-STUFF,SRC,DEST,CNT
GETB SRC,0
SUB STACK,1 >CNT
?PRG1: GETB SRC,CNT
PUTB DEST,CNT,STACK
DLESS? 'CNT,0 \?PRG1
RTRUE
.FUNCT INBUF-ADD,LEN,BEG,SLOT,DBEG,CTR=0,TMP,?TMP1
GET OOPS-TABLE,O-END >TMP
ZERO? TMP /?CCL3
SET 'DBEG,TMP
JUMP ?CND1
?CCL3: GET OOPS-TABLE,O-LENGTH >TMP
GETB AGAIN-LEXV,TMP >?TMP1
ADD TMP,1
GETB AGAIN-LEXV,STACK
ADD ?TMP1,STACK >DBEG
?CND1: ADD DBEG,LEN
PUT OOPS-TABLE,O-END,STACK
?PRG4: ADD DBEG,CTR >?TMP1
ADD BEG,CTR
GETB P-INBUF,STACK
PUTB OOPS-INBUF,?TMP1,STACK
INC 'CTR
EQUAL? CTR,LEN \?PRG4
PUTB AGAIN-LEXV,SLOT,DBEG
SUB SLOT,1
PUTB AGAIN-LEXV,STACK,LEN
RTRUE
.FUNCT WT?,PTR,BIT,B1=5,OFFS=P-P1OFF,TYP
GETB PTR,P-PSOFF >TYP
BTST TYP,BIT \FALSE
GRTR? B1,4 /TRUE
BAND TYP,P-P1BITS >TYP
EQUAL? TYP,B1 /?CND7
INC 'OFFS
?CND7: GETB PTR,OFFS
RSTACK
.FUNCT CLAUSE,PTR,VAL,WRD,OFF,NUM,ANDFLG=0,FIRST??=1,NW,LW=0,?TMP1
SUB P-NCN,1
MUL STACK,2 >OFF
ZERO? VAL /?CCL3
ADD P-PREP1,OFF >NUM
PUT P-ITBL,NUM,VAL
ADD NUM,1
PUT P-ITBL,STACK,WRD
ADD PTR,P-LEXELEN >PTR
JUMP ?CND1
?CCL3: INC 'P-LEN
?CND1: ZERO? P-LEN \?CND4
DEC 'P-NCN
RETURN -1
?CND4: ADD P-NC1,OFF >NUM
MUL PTR,2
ADD P-LEXV,STACK
PUT P-ITBL,NUM,STACK
GET P-LEXV,PTR
EQUAL? STACK,W?THE,W?A,W?AN \?PRG8
GET P-ITBL,NUM
ADD STACK,4
PUT P-ITBL,NUM,STACK
?PRG8: DLESS? 'P-LEN,0 \?CND10
ADD NUM,1 >?TMP1
MUL PTR,2
ADD P-LEXV,STACK
PUT P-ITBL,?TMP1,STACK
RETURN -1
?CND10: GET P-LEXV,PTR >WRD
ZERO? WRD \?CTR13
CALL NUMBER?,PTR >WRD
ZERO? WRD /?CCL14
?CTR13: ZERO? P-LEN \?CCL19
SET 'NW,0
JUMP ?CND17
?CCL19: ADD PTR,P-LEXELEN
GET P-LEXV,STACK >NW
?CND17: EQUAL? WRD,W?AND,W?COMMA \?CCL22
SET 'ANDFLG,TRUE-VALUE
JUMP ?CND12
?CCL22: EQUAL? WRD,W?ALL,W?ONE \?CCL24
EQUAL? NW,W?OF \?CND12
DEC 'P-LEN
ADD PTR,P-LEXELEN >PTR
JUMP ?CND12
?CCL24: EQUAL? WRD,W?THEN,W?PERIOD /?CTR27
CALL WT?,WRD,8
ZERO? STACK /?CCL28
GET P-ITBL,P-VERB
ZERO? STACK /?CCL28
ZERO? FIRST?? \?CCL28
?CTR27: INC 'P-LEN
ADD NUM,1 >?TMP1
MUL PTR,2
ADD P-LEXV,STACK
PUT P-ITBL,?TMP1,STACK
SUB PTR,P-LEXELEN
RSTACK
?CCL28: CALL WT?,WRD,128
ZERO? STACK /?CCL35
GRTR? P-LEN,0 \?CCL38
EQUAL? NW,W?OF \?CCL38
EQUAL? WRD,W?ALL,W?ONE \?CND12
?CCL38: CALL WT?,WRD,32,2
ZERO? STACK /?CCL42
ZERO? NW /?CCL42
CALL WT?,NW,128
ZERO? STACK \?CND12
?CCL42: ZERO? ANDFLG \?CCL47
EQUAL? NW,W?BUT,W?EXCEPT /?CCL47
EQUAL? NW,W?AND,W?COMMA /?CCL47
ADD NUM,1 >?TMP1
ADD PTR,2
MUL STACK,2
ADD P-LEXV,STACK
PUT P-ITBL,?TMP1,STACK
RETURN PTR
?CCL47: SET 'ANDFLG,FALSE-VALUE
JUMP ?CND12
?CCL35: ZERO? P-MERGED \?PRD53
ZERO? P-OFLAG \?PRD53
GET P-ITBL,P-VERB
ZERO? STACK /?CCL51
?PRD53: CALL WT?,WRD,32
ZERO? STACK \?CND12
CALL WT?,WRD,4
ZERO? STACK \?CND12
?CCL51: ZERO? ANDFLG /?CCL60
CALL WT?,WRD,16
ZERO? STACK \?CTR59
CALL WT?,WRD,64
ZERO? STACK /?CCL60
?CTR59: SUB PTR,4 >PTR
ADD PTR,2
PUT P-LEXV,STACK,W?THEN
ADD P-LEN,2 >P-LEN
?CND12: SET 'LW,WRD
SET 'FIRST??,FALSE-VALUE
ADD PTR,P-LEXELEN >PTR
JUMP ?PRG8
?CCL60: CALL WT?,WRD,8
ZERO? STACK \?CND12
CALL CANT-USE,PTR
RFALSE
?CCL14: CALL UNKNOWN-WORD,PTR
RFALSE
.FUNCT NUMBER?,PTR,CNT,BPTR,CHR,SUM=0,TIM=0,?TMP1
MUL PTR,2
ADD P-LEXV,STACK
GETB STACK,2 >CNT
MUL PTR,2
ADD P-LEXV,STACK
GETB STACK,3 >BPTR
?PRG1: DLESS? 'CNT,0 /?REP2
GETB P-INBUF,BPTR >CHR
EQUAL? CHR,58 \?CCL8
SET 'TIM,SUM
SET 'SUM,0
JUMP ?CND6
?CCL8: GRTR? SUM,10000 /FALSE
LESS? CHR,58 \FALSE
GRTR? CHR,47 \FALSE
MUL SUM,10 >?TMP1
SUB CHR,48
ADD ?TMP1,STACK >SUM
?CND6: INC 'BPTR
JUMP ?PRG1
?REP2: PUT P-LEXV,PTR,W?INTNUM
GRTR? SUM,1000 /FALSE
ZERO? TIM /?CND15
LESS? TIM,8 \?CCL21
ADD TIM,12 >TIM
JUMP ?CND19
?CCL21: GRTR? TIM,23 /FALSE
?CND19: MUL TIM,60
ADD SUM,STACK >SUM
?CND15: SET 'P-NUMBER,SUM
RETURN W?INTNUM
.FUNCT ORPHAN-MERGE,CNT=-1,TEMP,VERB,BEG,END,ADJ=0,WRD,?TMP1
SET 'P-OFLAG,FALSE-VALUE
GET P-ITBL,P-VERBN
GET STACK,0 >WRD
CALL WT?,WRD,64,1 >?TMP1
GET P-OTBL,P-VERB
EQUAL? ?TMP1,STACK /?CTR2
CALL WT?,WRD,32
ZERO? STACK /?CCL3
?CTR2: SET 'ADJ,TRUE-VALUE
JUMP ?CND1
?CCL3: CALL WT?,WRD,128,0
ZERO? STACK /?CND1
ZERO? P-NCN \?CND1
PUT P-ITBL,P-VERB,0
PUT P-ITBL,P-VERBN,0
ADD P-LEXV,2
PUT P-ITBL,P-NC1,STACK
ADD P-LEXV,6
PUT P-ITBL,P-NC1L,STACK
SET 'P-NCN,1
?CND1: GET P-ITBL,P-VERB >VERB
ZERO? VERB /?CCL11
ZERO? ADJ \?CCL11
GET P-OTBL,P-VERB
EQUAL? VERB,STACK \FALSE
?CCL11: EQUAL? P-NCN,2 /FALSE
GET P-OTBL,P-NC1
EQUAL? STACK,1 \?CCL18
GET P-ITBL,P-PREP1 >TEMP
GET P-OTBL,P-PREP1
EQUAL? TEMP,STACK /?CTR20
ZERO? TEMP \FALSE
?CTR20: ZERO? ADJ /?CCL26
ADD P-LEXV,2
PUT P-OTBL,P-NC1,STACK
GET P-ITBL,P-NC1L
ZERO? STACK \?CND27
ADD P-LEXV,6
PUT P-ITBL,P-NC1L,STACK
?CND27: ZERO? P-NCN \?CND24
SET 'P-NCN,1
JUMP ?CND24
?CCL26: GET P-ITBL,P-NC1
PUT P-OTBL,P-NC1,STACK
?CND24: GET P-ITBL,P-NC1L
PUT P-OTBL,P-NC1L,STACK
JUMP ?CND9
?CCL18: GET P-OTBL,P-NC2
EQUAL? STACK,1 \?CCL32
GET P-ITBL,P-PREP1 >TEMP
GET P-OTBL,P-PREP2
EQUAL? TEMP,STACK /?CTR34
ZERO? TEMP \FALSE
?CTR34: ZERO? ADJ /?CND38
ADD P-LEXV,2
PUT P-ITBL,P-NC1,STACK
GET P-ITBL,P-NC1L
ZERO? STACK \?CND38
ADD P-LEXV,6
PUT P-ITBL,P-NC1L,STACK
?CND38: GET P-ITBL,P-NC1
PUT P-OTBL,P-NC2,STACK
GET P-ITBL,P-NC1L
PUT P-OTBL,P-NC2L,STACK
SET 'P-NCN,2
JUMP ?CND9
?CCL32: ZERO? P-ACLAUSE /?CND9
EQUAL? P-NCN,1 /?CCL45
ZERO? ADJ \?CCL45
SET 'P-ACLAUSE,FALSE-VALUE
RFALSE
?CCL45: GET P-ITBL,P-NC1 >BEG
ZERO? ADJ /?CND48
ADD P-LEXV,2 >BEG
SET 'ADJ,FALSE-VALUE
?CND48: GET P-ITBL,P-NC1L >END
?PRG50: GET BEG,0 >WRD
EQUAL? BEG,END \?CCL54
ZERO? ADJ /?CCL57
CALL ACLAUSE-WIN,ADJ
JUMP ?CND9
?CCL57: SET 'P-ACLAUSE,FALSE-VALUE
RFALSE
?CCL54: ZERO? ADJ \?CCL59
GETB WRD,P-PSOFF
BTST STACK,32 /?CTR58
EQUAL? WRD,W?ALL,W?ONE \?CCL59
?CTR58: SET 'ADJ,WRD
?CND52: ADD BEG,P-WORDLEN >BEG
ZERO? END \?PRG50
SET 'END,BEG
SET 'P-NCN,1
SUB BEG,4
PUT P-ITBL,P-NC1,STACK
PUT P-ITBL,P-NC1L,BEG
JUMP ?PRG50
?CCL59: EQUAL? WRD,W?ONE \?CCL65
CALL ACLAUSE-WIN,ADJ
JUMP ?CND9
?CCL65: GETB WRD,P-PSOFF
BTST STACK,128 \?CND52
EQUAL? WRD,P-ANAM \?CCL69
CALL ACLAUSE-WIN,ADJ
JUMP ?CND9
?CCL69: CALL NCLAUSE-WIN
?CND9: GET P-OVTBL,0
PUT P-VTBL,0,STACK
GETB P-OVTBL,2
PUTB P-VTBL,2,STACK
GETB P-OVTBL,3
PUTB P-VTBL,3,STACK
PUT P-OTBL,P-VERBN,P-VTBL
PUTB P-VTBL,2,0
?PRG72: IGRTR? 'CNT,P-ITBLLEN \?CCL76
SET 'P-MERGED,TRUE-VALUE
RTRUE
?CCL76: GET P-OTBL,CNT
PUT P-ITBL,CNT,STACK
JUMP ?PRG72
.FUNCT ACLAUSE-WIN,ADJ
GET P-OTBL,P-VERB
PUT P-ITBL,P-VERB,STACK
PUT P-CCTBL,CC-SBPTR,P-ACLAUSE
ADD P-ACLAUSE,1
PUT P-CCTBL,CC-SEPTR,STACK
PUT P-CCTBL,CC-DBPTR,P-ACLAUSE
ADD P-ACLAUSE,1
PUT P-CCTBL,CC-DEPTR,STACK
CALL CLAUSE-COPY,P-OTBL,P-OTBL,ADJ
GET P-OTBL,P-NC2
ZERO? STACK /?PEN1
SET 'P-NCN,2
?PEN1: SET 'P-ACLAUSE,FALSE-VALUE
RTRUE
.FUNCT NCLAUSE-WIN
PUT P-CCTBL,CC-SBPTR,P-NC1
PUT P-CCTBL,CC-SEPTR,P-NC1L
PUT P-CCTBL,CC-DBPTR,P-ACLAUSE
ADD P-ACLAUSE,1
PUT P-CCTBL,CC-DEPTR,STACK
CALL CLAUSE-COPY,P-ITBL,P-OTBL
GET P-OTBL,P-NC2
ZERO? STACK /?PEN1
SET 'P-NCN,2
?PEN1: SET 'P-ACLAUSE,FALSE-VALUE
RTRUE
.FUNCT WORD-PRINT,CNT,BUF
?PRG1: DLESS? 'CNT,0 /TRUE
GETB P-INBUF,BUF
PRINTC STACK
INC 'BUF
JUMP ?PRG1
.FUNCT UNKNOWN-WORD,PTR,BUF,?TMP1
PUT OOPS-TABLE,O-PTR,PTR
EQUAL? PRSA,V?SAY \?PRG5
PRINTI "Nothing happens."
CRLF
RFALSE
?PRG5: PRINTI "I don't know the word """
MUL PTR,2 >BUF
ADD P-LEXV,BUF
GETB STACK,2 >?TMP1
ADD P-LEXV,BUF
GETB STACK,3
CALL WORD-PRINT,?TMP1,STACK
PRINTI """."
CRLF
SET 'QUOTE-FLAG,FALSE-VALUE
SET 'P-OFLAG,FALSE-VALUE
RETURN P-OFLAG
.FUNCT CANT-USE,PTR,BUF,?TMP1
EQUAL? PRSA,V?SAY \?PRG5
PRINTI "Nothing happens."
CRLF
RFALSE
?PRG5: PRINTI "You used the word """
MUL PTR,2 >BUF
ADD P-LEXV,BUF
GETB STACK,2 >?TMP1
ADD P-LEXV,BUF
GETB STACK,3
CALL WORD-PRINT,?TMP1,STACK
PRINTI """ in a way that I don't understand."
CRLF
SET 'QUOTE-FLAG,FALSE-VALUE
SET 'P-OFLAG,FALSE-VALUE
RETURN P-OFLAG
.FUNCT GET-PREP,SYN,WHICH,PREP
EQUAL? WHICH,1 \?CCL3
GETB SYN,P-SPREP1 >PREP
JUMP ?CND1
?CCL3: GETB SYN,P-SPREP2 >PREP
?CND1: BAND PREP,63 >PREP
ZERO? PREP /FALSE
ADD PREP,192
RSTACK
.FUNCT SYNTAX-CHECK,SYN,LEN,NUM,OBJ,DRIVE1=0,DRIVE2=0,PREP,VERB,TMP,?TMP2,?TMP1
GET P-ITBL,P-VERB >VERB
ZERO? VERB \?CND1
PRINTI "There was no verb in that sentence!"
CRLF
RFALSE
?CND1: SUB 255,VERB
GET VERBS,STACK >SYN
GETB SYN,0 >LEN
INC 'SYN
?PRG5: GETB SYN,P-SPREP1
DIV STACK,64 >NUM
GRTR? P-NCN,NUM /?CND7
LESS? NUM,1 /?CCL11
ZERO? P-NCN \?CCL11
GET P-ITBL,P-PREP1 >PREP
ZERO? PREP /?CTR10
CALL GET-PREP,SYN,1
EQUAL? PREP,STACK \?CCL11
?CTR10: SET 'DRIVE1,SYN
JUMP ?CND7
?CCL11: CALL GET-PREP,SYN,1 >?TMP1
GET P-ITBL,P-PREP1
EQUAL? ?TMP1,STACK \?CND7
EQUAL? NUM,2 \?CCL20
EQUAL? P-NCN,1 \?CCL20
SET 'DRIVE2,SYN
?CND7: DLESS? 'LEN,1 \?CCL28
ZERO? DRIVE1 \?REP6
ZERO? DRIVE2 \?REP6
PRINTI "That sentence isn't one I recognize."
CRLF
RFALSE
?CCL20: GRTR? NUM,1 \?CCL23
CALL GET-PREP,SYN,2 >?TMP1
GET P-ITBL,P-PREP2
EQUAL? ?TMP1,STACK \?CND7
?CCL23: CALL SYNTAX-FOUND,SYN
RTRUE
?CCL28: ZERO? NUM \?CCL38
ADD SYN,P-SYNLEN-0 >SYN
JUMP ?PRG5
?CCL38: EQUAL? NUM,1 \?CCL40
ADD SYN,P-SYNLEN-1 >SYN
JUMP ?PRG5
?CCL40: ADD SYN,P-SYNLEN-2 >SYN
JUMP ?PRG5
?REP6: ZERO? DRIVE1 /?CCL43
GETB DRIVE1,P-SFWIM1 >?TMP2
GETB DRIVE1,P-SLOC1 >?TMP1
CALL GET-PREP,DRIVE1,1
CALL GWIM,?TMP2,?TMP1,STACK >OBJ
ZERO? OBJ /?CCL43
PUT P-PRSO,P-MATCHLEN,1
PUT P-PRSO,1,OBJ
CALL SYNTAX-FOUND,DRIVE1
RSTACK
?CCL43: ZERO? DRIVE2 /?CCL47
GETB DRIVE2,P-SFWIM2 >?TMP2
GETB DRIVE2,P-SLOC2 >?TMP1
CALL GET-PREP,DRIVE2,2
CALL GWIM,?TMP2,?TMP1,STACK >OBJ
ZERO? OBJ /?CCL47
PUT P-PRSI,P-MATCHLEN,1
PUT P-PRSI,1,OBJ
CALL SYNTAX-FOUND,DRIVE2
RSTACK
?CCL47: EQUAL? VERB,ACT?FIND \?CCL51
PRINTI "That question can't be answered."
CRLF
RFALSE
?CCL51: EQUAL? WINNER,ADVENTURER /?CCL55
CALL CANT-ORPHAN
RSTACK
?CCL55: CALL ORPHAN,DRIVE1,DRIVE2
PRINTI "What do you want to "
GET P-OTBL,P-VERBN >TMP
ZERO? TMP \?CCL60
PRINTI "tell"
JUMP ?CND58
?CCL60: GETB P-VTBL,2
ZERO? STACK \?CCL64
GET TMP,0
PRINTB STACK
JUMP ?CND58
?CCL64: GETB TMP,2 >?TMP1
GETB TMP,3
CALL WORD-PRINT,?TMP1,STACK
PUTB P-VTBL,2,0
?CND58: ZERO? DRIVE2 /?CND65
PRINTC 32
CALL THING-PRINT,TRUE-VALUE,TRUE-VALUE
?CND65: SET 'P-OFLAG,TRUE-VALUE
ZERO? DRIVE1 /?CCL71
CALL GET-PREP,DRIVE1,1
JUMP ?CND69
?CCL71: CALL GET-PREP,DRIVE2,2
?CND69: CALL PREP-PRINT,STACK
PRINTC 63
CRLF
RFALSE
.FUNCT CANT-ORPHAN
PRINTI """I don't understand! What are you referring to?"""
CRLF
RFALSE
.FUNCT ORPHAN,D1,D2,CNT=-1
ZERO? P-MERGED \?CND1
PUT P-OCLAUSE,P-MATCHLEN,0
?CND1: GET P-VTBL,0
PUT P-OVTBL,0,STACK
GETB P-VTBL,2
PUTB P-OVTBL,2,STACK
GETB P-VTBL,3
PUTB P-OVTBL,3,STACK
?PRG3: IGRTR? 'CNT,P-ITBLLEN /?REP4
GET P-ITBL,CNT
PUT P-OTBL,CNT,STACK
JUMP ?PRG3
?REP4: EQUAL? P-NCN,2 \?CND8
PUT P-CCTBL,CC-SBPTR,P-NC2
PUT P-CCTBL,CC-SEPTR,P-NC2L
PUT P-CCTBL,CC-DBPTR,P-NC2
PUT P-CCTBL,CC-DEPTR,P-NC2L
CALL CLAUSE-COPY,P-ITBL,P-OTBL
?CND8: LESS? P-NCN,1 /?CND10
PUT P-CCTBL,CC-SBPTR,P-NC1
PUT P-CCTBL,CC-SEPTR,P-NC1L
PUT P-CCTBL,CC-DBPTR,P-NC1
PUT P-CCTBL,CC-DEPTR,P-NC1L
CALL CLAUSE-COPY,P-ITBL,P-OTBL
?CND10: ZERO? D1 /?CCL14
CALL GET-PREP,D1,1
PUT P-OTBL,P-PREP1,STACK
PUT P-OTBL,P-NC1,1
RTRUE
?CCL14: ZERO? D2 /FALSE
CALL GET-PREP,D2,2
PUT P-OTBL,P-PREP2,STACK
PUT P-OTBL,P-NC2,1
RTRUE
.FUNCT THING-PRINT,PRSO?,THE?=0,BEG,END
ZERO? PRSO? /?CCL3
GET P-ITBL,P-NC1 >BEG
GET P-ITBL,P-NC1L >END
JUMP ?CND1
?CCL3: GET P-ITBL,P-NC2 >BEG
GET P-ITBL,P-NC2L >END
?CND1: CALL BUFFER-PRINT,BEG,END,THE?
RSTACK
.FUNCT BUFFER-PRINT,BEG,END,CP,NOSP=1,WRD,FIRST??=1,PN=0,Q?=0,?TMP1
?PRG1: EQUAL? BEG,END /TRUE
GET BEG,0 >WRD
EQUAL? WRD,W?COMMA \?CCL8
PRINTI ", "
JUMP ?CND6
?CCL8: ZERO? NOSP /?PRG13
SET 'NOSP,FALSE-VALUE
JUMP ?CND6
?PRG13: PRINTC 32
?CND6: EQUAL? WRD,W?PERIOD,W?COMMA \?CCL17
SET 'NOSP,TRUE-VALUE
JUMP ?CND3
?CCL17: EQUAL? WRD,W?ME \?CCL19
PRINTD ME
SET 'PN,TRUE-VALUE
JUMP ?CND3
?CCL19: EQUAL? WRD,W?INTNUM \?CCL21
PRINTN P-NUMBER
SET 'PN,TRUE-VALUE
JUMP ?CND3
?CCL21: ZERO? FIRST?? /?CND22
ZERO? PN \?CND22
ZERO? CP /?CND22
PRINTI "the "
?CND22: ZERO? P-OFLAG \?CTR30
ZERO? P-MERGED /?CCL31
?CTR30: PRINTB WRD
JUMP ?CND29
?CCL31: EQUAL? WRD,W?IT \?CCL35
CALL ACCESSIBLE?,P-IT-OBJECT
ZERO? STACK /?CCL35
PRINTD P-IT-OBJECT
JUMP ?CND29
?CCL35: GETB BEG,2 >?TMP1
GETB BEG,3
CALL WORD-PRINT,?TMP1,STACK
?CND29: SET 'FIRST??,FALSE-VALUE
?CND3: ADD BEG,P-WORDLEN >BEG
JUMP ?PRG1
.FUNCT PREP-PRINT,PREP,WRD
ZERO? PREP /FALSE
PRINTC 32
CALL PREP-FIND,PREP >WRD
PRINTB WRD
RTRUE
.FUNCT CLAUSE-COPY,SRC,DEST,INSRT=0,BEG,END,?TMP1
GET P-CCTBL,CC-SBPTR
GET SRC,STACK >BEG
GET P-CCTBL,CC-SEPTR
GET SRC,STACK >END
GET P-CCTBL,CC-DBPTR >?TMP1
GET P-OCLAUSE,P-MATCHLEN
MUL STACK,P-LEXELEN
ADD STACK,2
ADD P-OCLAUSE,STACK
PUT DEST,?TMP1,STACK
?PRG1: EQUAL? BEG,END \?CCL5
GET P-CCTBL,CC-DEPTR >?TMP1
GET P-OCLAUSE,P-MATCHLEN
MUL STACK,P-LEXELEN
ADD STACK,2
ADD P-OCLAUSE,STACK
PUT DEST,?TMP1,STACK
RTRUE
?CCL5: ZERO? INSRT /?CND6
GET BEG,0
EQUAL? P-ANAM,STACK \?CND6
CALL CLAUSE-ADD,INSRT
?CND6: GET BEG,0
CALL CLAUSE-ADD,STACK
ADD BEG,P-WORDLEN >BEG
JUMP ?PRG1
.FUNCT CLAUSE-ADD,WRD,PTR
GET P-OCLAUSE,P-MATCHLEN
ADD STACK,2 >PTR
SUB PTR,1
PUT P-OCLAUSE,STACK,WRD
PUT P-OCLAUSE,PTR,0
PUT P-OCLAUSE,P-MATCHLEN,PTR
RTRUE
.FUNCT PREP-FIND,PREP,CNT=0,SIZE
GET PREPOSITIONS,0
MUL STACK,2 >SIZE
?PRG1: IGRTR? 'CNT,SIZE /FALSE
GET PREPOSITIONS,CNT
EQUAL? STACK,PREP \?PRG1
SUB CNT,1
GET PREPOSITIONS,STACK
RSTACK
.FUNCT SYNTAX-FOUND,SYN
SET 'P-SYNTAX,SYN
GETB SYN,P-SACTION >PRSA
RETURN PRSA