-
Notifications
You must be signed in to change notification settings - Fork 21
/
parser.zap
1563 lines (1480 loc) · 31.8 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
.SEGMENT "0"
.FUNCT INIT-STATUS-LINE:ANY:0:0
SPLIT 1
SCREEN S-WINDOW
CURSET 1,1
HLIGHT H-INVERSE
ERASE 1
HLIGHT H-NORMAL
SCREEN S-TEXT
RTRUE
.FUNCT UPDATE-STATUS-LINE:ANY:0:0,?TMP2,?TMP1
SCREEN S-WINDOW
HLIGHT H-INVERSE
EQUAL? HERE,OLD-HERE /?CND1
SET 'OLD-HERE,HERE
CURSET 1,1
ERASE 1
CURSET 1,1
PRINTD HERE
?CND1: GETB 0,33 >?TMP1
CALL2 DIGITS,SCORE >?TMP2
CALL2 DIGITS,MOVES
ADD ?TMP2,STACK
SUB ?TMP1,STACK
CURSET 1,STACK
PRINTN SCORE
PRINTC 47
PRINTN MOVES
HLIGHT H-NORMAL
SCREEN S-TEXT
RTRUE
.FUNCT DIGITS:ANY:1:1,N,D
SET 'D,1
LESS? N,0 \?PRG3
INC 'D
SUB 0,N >N
?PRG3: DIV N,10 >N
ZERO? N /?REP4
INC 'D
JUMP ?PRG3
?REP4: RETURN D
.FUNCT READ-INPUT:ANY:0:0
PRINTC 62
PUTB P-INBUF,1,0
ZERO? DEMO-VERSION? /?CCL4
ICALL READ-DEMO,P-INBUF,P-LEXV
JUMP ?CND2
?CCL4: READ P-INBUF,P-LEXV
?CND2: CALL1 SCRIPT-INBUF
RSTACK
.FUNCT SCRIPT-INBUF:ANY:0:0,BUF,CNT,N,CHR
GETB P-INBUF,1 >N
DIROUT D-SCREEN-OFF
ADD 1,P-INBUF >BUF
?PRG1: IGRTR? 'CNT,N /?REP2
GETB BUF,CNT >CHR
LESS? CHR,97 /?CCL8
GRTR? CHR,122 /?CCL8
SUB CHR,32
PRINTC STACK
JUMP ?PRG1
?CCL8: PRINTC CHR
JUMP ?PRG1
?REP2: CRLF
DIROUT D-SCREEN-ON
RTRUE
.FUNCT SPECIAL-CONTRACTION?:ANY:1:1,PTR
RFALSE
.FUNCT EXPAND-BE-CONTRACTIONS:ANY:0:0,LEN,PTR,OPTR,N,WD,SPWD,L,?TMP1
GETB P-LEXV,P-LEXWORDS >LEN
SET 'PTR,P-LEXV+2
SET 'OPTR,PTR
SET 'L,LEN
?PRG1: SET 'SPWD,FALSE-VALUE
DLESS? 'L,0 \?CCL5
PUTB P-LEXV,P-LEXWORDS,LEN
RTRUE
?CCL5: GET PTR,0 >WD
ZERO? WD /?CCL7
GET PTR,P-LEXELEN
EQUAL? STACK,W?APOSTROPHE \?CCL7
GET P-QA-WORDS1,0
INTBL? WD,P-QA-WORDS1+2,STACK >N \?PRD12
SUB N,P-QA-WORDS1
DIV STACK,2 >N
GET P-QA-WORDS2,N >?TMP1
GET PTR,4
EQUAL? ?TMP1,STACK /?CTR6
?PRD12: CALL2 SPECIAL-CONTRACTION?,PTR >SPWD
ZERO? SPWD /?CCL7
?CTR6: ZERO? SPWD /?CCL17
PUSH 8
JUMP ?CND15
?CCL17: PUSH 4
?CND15: ADD PTR,STACK >?TMP1
MUL L,4
COPYT ?TMP1,PTR,STACK
ZERO? SPWD /?CCL20
PUT PTR,0,SPWD
DEC 'L
DEC 'LEN
JUMP ?CND18
?CCL20: GET P-QB-WORDS-1,N >WD
PUT PTR,0,WD
GET P-QB-WORDS-2,N >WD
PUT PTR,P-LEXELEN,WD
?CND18: DEC 'L
DEC 'LEN
JUMP ?PRG1
?CCL7: EQUAL? WD,W?APOSTROPHE \?CCL22
GET PTR,P-LEXELEN
EQUAL? STACK,W?S /?CCL22
EQUAL? OPTR,PTR /?CCL22
SUB PTR,4 >WD
ZERO? WD /?CCL22
GETB WD,2
ADD -1,STACK >?TMP1
GETB WD,3
ADD ?TMP1,STACK
GETB P-INBUF,STACK
EQUAL? STACK,115,122 \?CCL22
SUB PTR,P-LEXV
DIV STACK,2
ADD P-LEXELEN,STACK
ICALL MAKE-ROOM-FOR-TOKENS,1,P-LEXV,STACK
PUT PTR,P-LEXELEN,W?S
INC 'L
INC 'LEN
JUMP ?PRG1
?CCL22: ADD PTR,4 >PTR
JUMP ?PRG1
.FUNCT TELL-THE:ANY:1:1,OBJ,TMP
EQUAL? OBJ,PLAYER \?CCL3
PRINTI "you"
RTRUE
?CCL3: CALL2 GET-OWNER,OBJ >TMP
ZERO? TMP /?CCL6
EQUAL? TMP,PLAYER \?CCL9
PRINTI "your "
JUMP ?CND4
?CCL9: EQUAL? TMP,OBJ /?CND4
ICALL2 TELL-THE,TMP
PRINTI "'s "
JUMP ?CND4
?CCL6: FSET? OBJ,NARTICLEBIT /?CND4
PRINTI "the "
?CND4: PRINTD OBJ
RTRUE
.FUNCT TELL-CTHE:ANY:1:1,OBJ,TMP
EQUAL? OBJ,PLAYER \?CCL3
PRINTI "You"
RTRUE
?CCL3: CALL2 GET-OWNER,OBJ >TMP
ZERO? TMP /?CCL6
EQUAL? TMP,PLAYER \?CCL9
PRINTI "Your "
JUMP ?CND4
?CCL9: EQUAL? TMP,OBJ /?CND4
ICALL2 TELL-CTHE,TMP
PRINTI "'s "
JUMP ?CND4
?CCL6: FSET? OBJ,NARTICLEBIT /?CND4
PRINTI "The "
?CND4: PRINTD OBJ
RTRUE
.FUNCT NAKED-DIR?:ANY:0:0,WCNUM,LEN
GET TLEXV,0 >LEN
ZERO? LEN /FALSE
GET LEN,4 >WCNUM
ZERO? WCNUM \?CND3
GET LEN,3 >LEN
GET LEN,4 >WCNUM
?CND3: BTST WCNUM,32768 /FALSE
BAND WCNUM,64
BAND STACK,32767
ZERO? STACK /FALSE
EQUAL? P-LEN,1 \?CCL11
RETURN LEN
?CCL11: SUB TLEXV,P-LEXV
LESS? STACK,234 /?CND9
RETURN LEN
?CND9: GET TLEXV,P-LEXELEN >WCNUM
EQUAL? WCNUM,W?COMMA,W?AND \?CND13
RETURN LEN
?CND13: GET WCNUM,4 >WCNUM
BAND WCNUM,32768
EQUAL? STACK,-32768 \FALSE
BAND WCNUM,32776
BAND STACK,32767
ZERO? STACK /FALSE
RETURN LEN
.FUNCT PARSER:ANY:0:0,OWINNER,LEN,N,PV,?TMP1
ZERO? P-DBUG /?CND2
PRINTI "[Reset of PMEM: "
PRINTN PMEM-WORDS-USED
PRINTI " words used.]
"
?CND2: ICALL1 PMEM-RESET
SET 'ERROR-PRIORITY,255
SET 'ERROR-STRING,FALSE-VALUE
SET 'OWINNER,WINNER
GRTR? P-CONT,0 \?CCL6
SET 'TLEXV,P-CONT
ZERO? VERBOSITY /?CND7
EQUAL? PLAYER,WINNER \?CND7
CRLF
?CND7: SET 'P-CONT,FALSE-VALUE
JUMP ?CND4
?CCL6: SET 'WINNER,PLAYER
ZERO? P-OFLAG \?CND11
GET OOPS-TABLE,O-PTR
ZERO? STACK \?CND11
PUT OOPS-TABLE,O-END,FALSE-VALUE
?CND11: LOC WINNER
IN? STACK,ROOMS \?CND15
LOC WINNER >HERE
?CND15: ZERO? LIT /?CCL18
EQUAL? HERE,LIT /?CND17
IN? LIT,HERE /?CND17
CALL2 VISIBLE?,LIT
ZERO? STACK \?CND17
?CCL18: CALL1 LIT? >LIT
?CND17: GET 0,8
BTST STACK,F-REFRESH \?CND24
ICALL1 V-$REFRESH
?CND24: ZERO? VERBOSITY /?CND26
CRLF
?CND26: ICALL1 UPDATE-STATUS-LINE
ICALL1 READ-INPUT
GETB P-LEXV,P-LEXWORDS >LEN
ZERO? LEN /?CND29
INTBL? W?QUOTE,P-LEXV+2,LEN,132 >N \?CND29
ICALL FIX-QUOTATIONS,LEN,N
?CND29: ICALL1 EXPAND-BE-CONTRACTIONS
GETB P-LEXV,P-LEXWORDS >P-LEN
SET 'TLEXV,P-LEXV+2
?CND4: GET TLEXV,0
EQUAL? STACK,W?PERIOD,W?THEN \?CND33
ADD TLEXV,4 >TLEXV
DEC 'P-LEN
?CND33: GET TLEXV,0
EQUAL? STACK,W?YOU \?CND35
ICALL1 IGNORE-FIRST-WORD
?CND35: GET TLEXV,0
EQUAL? STACK,W?GO,W?TO \?CND37
ICALL1 IGNORE-FIRST-WORD
?CND37: ZERO? P-LEN \?CND39
ICALL1 BEG-PARDON
RFALSE
?CND39: CALL1 NAKED-DIR? >LEN
ZERO? LEN /?CCL43
PUT STATE-STACK,0,20
PUT DATA-STACK,0,20
XPUSH LEN,DATA-STACK /?BOGUS44
?BOGUS44: ICALL2 RED-SD,1
SET 'P-CONT,FALSE-VALUE
SET 'P-OFLAG,0
SET 'P-WORDS-AGAIN,1
PUT OOPS-TABLE,O-END,FALSE-VALUE
PUT OOPS-TABLE,O-START,TLEXV
PUTB P-LEXV,P-LEXWORDS,P-LEN
COPYT P-LEXV,G-LEXV,LEXV-LENGTH-BYTES
COPYT P-INBUF,G-INBUF,61
PUT PARSE-RESULT,13,0
DEC 'P-LEN
LESS? 0,P-LEN \TRUE
ADD TLEXV,4 >TLEXV
GET TLEXV,0 >LEN
ZERO? LEN /TRUE
GET LEN,4 >LEN
ZERO? LEN /TRUE
BAND LEN,32768
EQUAL? STACK,-32768 \TRUE
BAND LEN,32776
BAND STACK,32767
ZERO? STACK /TRUE
SET 'P-WORDS-AGAIN,P-WORD-NUMBER
DLESS? 'P-LEN,1 /TRUE
ADD TLEXV,4 >P-CONT
RTRUE
?CCL43: GET TLEXV,0
EQUAL? STACK,W?OOPS,W?O \?CCL55
CALL2 DO-OOPS,OWINNER
ZERO? STACK \?CND41
RFALSE
?CCL55: ZERO? P-OFLAG \?CND41
LESS? P-CONT,1 \?CND41
PUT OOPS-TABLE,O-END,FALSE-VALUE
?CND41: SET 'P-CONT,FALSE-VALUE
GET TLEXV,0
EQUAL? STACK,W?AGAIN,W?G \?CCL63
CALL2 DO-AGAIN,OWINNER
ZERO? STACK \?CND61
RFALSE
?CCL63: PUTB P-LEXV,P-LEXWORDS,P-LEN
COPYT P-LEXV,G-LEXV,LEXV-LENGTH-BYTES
COPYT P-INBUF,G-INBUF,61
PUT OOPS-TABLE,O-START,TLEXV
PUT OOPS-TABLE,O-LENGTH,P-LEN
GET OOPS-TABLE,O-END
ZERO? STACK \?CND61
GETB P-LEXV,P-LEXWORDS
MUL 4,STACK >LEN
DEC 'LEN
GETB TLEXV,LEN >?TMP1
DEC 'LEN
GETB TLEXV,LEN
ADD ?TMP1,STACK
PUT OOPS-TABLE,O-END,STACK
?CND61: SET 'P-WON,FALSE-VALUE
SET 'P-WALK-DIR,FALSE-VALUE
CALL2 PARSE-IT,FALSE-VALUE >PV
?PRG68: ZERO? PV \?CCL72
CALL1 PRINT-PARSER-FAILURE >PV
JUMP ?PRG68
?CCL72: EQUAL? PV,1 /FALSE
PUT OOPS-TABLE,O-PTR,FALSE-VALUE
GET PV,4 >PRSA
CALL1 GAME-VERB?
ZERO? STACK \?CND75
SET 'P-OFLAG,0
?CND75: GET PV,0 >LEN
EQUAL? LEN,W?TWICE,W?THRICE \?CND77
GET OOPS-TABLE,O-START
INTBL? LEN,STACK,P-WORDS-AGAIN,132 >N \?CND77
ICALL CHANGE-LEXV,N,W?ONCE
EQUAL? LEN,W?THRICE \?CCL83
PUSH 2
JUMP ?CND81
?CCL83: PUSH 1
?CND81: ICALL2 DO-IT-AGAIN,STACK
CALL2 PARSE-IT,FALSE-VALUE >PV
JUMP ?PRG68
?CND77: GET GWIM-MSG,1
ZERO? STACK /?CND84
ICALL1 TELL-GWIM-MSG
PUT GWIM-MSG,1,0
?CND84: GET GWIM-MSG,2
ZERO? STACK /TRUE
PRINTI "["""
GET GWIM-MSG,2
ICALL2 NP-PRINT,STACK
PRINTI """ meaning "
GET GWIM-MSG,3
ICALL2 TELL-THE,STACK
PRINTI "]
"
PUT GWIM-MSG,2,0
RTRUE
.FUNCT GAME-VERB?:ANY:0:0
GET GAME-VERB-TABLE,0
INTBL? PRSA,GAME-VERB-TABLE+2,STACK /TRUE
EQUAL? PRSA,V?$UNRECORD /TRUE
EQUAL? PRSA,V?$RECORD,V?$COMMAND,V?$RANDOM /TRUE
RFALSE
.FUNCT RED-SD:ANY:0:2,N,TYP,V,SYN,NEW-OBJECT
SET 'V,W?WALK
PUT PARSE-RESULT,1,V
GET V,3
GET STACK,2
ADD STACK,2 >SYN
PUT PARSE-RESULT,3,SYN
GET SYN,0
PUT PARSE-RESULT,4,STACK
PUT PARSE-RESULT,7,FALSE-VALUE
POP DATA-STACK
GETB STACK,6 >P-WALK-DIR
CALL DO-PMEM-ALLOC,4,NOUN-PHRASE-MIN-LENGTH >NEW-OBJECT
PUT NEW-OBJECT,1,1
PUT NEW-OBJECT,3,P-WALK-DIR
PUT PARSE-RESULT,5,NEW-OBJECT
RTRUE
.FUNCT P-P:ANY:1:1,X
CALL2 PMEM?,X
ZERO? STACK /?CCL3
GETB X,1
EQUAL? STACK,1 \?CCL6
PRINTI "#ADJS["
ICALL2 ADJS-PRINT,X
PRINTC 93
RTRUE
?CCL6: GETB X,1
EQUAL? STACK,2 \?CCL8
PRINTI "#NP["
ICALL2 NP-PRINT,X
PRINTC 93
RTRUE
?CCL8: GETB X,1
EQUAL? STACK,3 \?CCL10
PRINTI "#NPP["
?PRG11: GET X,2
ZERO? STACK /?CND13
GET X,2
ICALL2 P-P,STACK
PRINTC 32
?CND13: GET X,3
ZERO? STACK /?CND15
GET X,3
ICALL2 P-P,STACK
PRINTC 32
?CND15: GET X,1 >X
ZERO? X \?PRG11
PRINTC 93
RTRUE
?CCL10: GETB X,1
EQUAL? STACK,4 \?CCL20
PRINTI "#NOUN-PHRASE["
ICALL2 NP-PRINT,X
PRINTC 93
RTRUE
?CCL20: GETB X,1
EQUAL? STACK,5 /?CTR21
GETB X,1
EQUAL? STACK,6 \?CCL22
?CTR21: PRINTI "#PP["
PRINTI "W?"
GET X,1
PRINTB STACK
PRINTC 32
GET X,2
ICALL2 P-P,STACK
PRINTC 93
RTRUE
?CCL22: PRINTI "#PMEM[]"
RTRUE
?CCL3: EQUAL? X,PARSE-RESULT \?CCL26
PRINTI "RESULT"
RTRUE
?CCL26: LESS? VOCAB,PRSTBL \?PRD30
LESS? VOCAB,X \?PRD30
LESS? X,PRSTBL /?CTR27
?PRD30: LESS? 0,VOCAB \?CCL28
LESS? PRSTBL,0 \?CCL28
LESS? VOCAB,X /?CTR27
LESS? X,PRSTBL \?CCL28
?CTR27: PRINTI "W?"
PRINTB X
RTRUE
?CCL28: PRINTN X
RTRUE
.FUNCT PARSE-IT:ANY:0:1,V,RES,NUM,W,SAV-LEXV,TMP,TV,T2,?TMP1
SET 'SPLITS,0
PUT SPLIT-STACK,0,0
SET 'ERROR-PRIORITY,255
PUT ERROR-ARGS,1,0
SET 'P-OLEN,P-LEN
SET 'OTLEXV,TLEXV
SET 'W,WINNER
SET 'SAV-LEXV,TLEXV
?PRG1: INC 'NUM
ZERO? P-DBUG /?CND3
PRINTI "[PASS "
PRINTN NUM
PRINTI "]
"
?CND3: ICALL2 BE-PATIENT,NUM
PUT STATE-STACK,0,20
XPUSH 1,STATE-STACK /?BOGUS5
?BOGUS5: PUT DATA-STACK,0,20
ZERO? P-DBUG /?CND6
PRINTI "[Reset of PMEM: "
PRINTN PMEM-WORDS-USED
PRINTI " words used.]
"
?CND6: ICALL1 PMEM-RESET
SET 'P-WORD-NUMBER,0
SET 'TLEXV,SAV-LEXV
SET 'P-LEN,P-OLEN
SET 'WINNER,W
COPYT GWIM-MSG,0,8
COPYT PARSE-RESULT,0,PARSE-RESULT-LEN
CALL2 PARSE-SENTENCE,PARSE-RESULT >RES
EQUAL? RES,PARSER-RESULT-AGAIN \?CCL10
PUT SPLIT-STACK,0,0
SET 'ERROR-PRIORITY,255
SET 'P-OLEN,P-LEN
SET 'SAV-LEXV,TLEXV
JUMP ?PRG1
?CCL10: LESS? RES,PARSER-RESULT-WON \?REP2
GET SPLIT-STACK,0
ZERO? STACK /?REP2
ZERO? RES /?REP2
?PRG16: GET SPLIT-STACK,0 >T2
SUB T2,1
GET SPLIT-STACK,STACK >TV
BAND TV,65280
ZERO? STACK /?CCL20
GET SPLIT-STACK,T2 >TMP
BTST TMP,32768 /?CCL23
ADD TV,6
CALL GET-TERMINAL-ACTION,TMP,STACK,1 >TV
JUMP ?CND21
?CCL23: BAND TMP,32767 >?TMP1
ADD TV,6
CALL GET-TERMINAL-ACTION,?TMP1,STACK,0 >TV
?CND21: ZERO? TV \?CCL26
SUB T2,2 >T2
PUT SPLIT-STACK,0,T2
JUMP ?CND18
?CCL26: SUB T2,1
PUT SPLIT-STACK,STACK,TV
JUMP ?REP17
?CCL20: GET SPLIT-STACK,T2 >TMP
EQUAL? TMP,TV \?CCL28
SUB T2,2 >T2
PUT SPLIT-STACK,0,T2
?CND18: ZERO? T2 \?PRG16
?REP17: GET SPLIT-STACK,0
ZERO? STACK /?REP2
ZERO? P-DBUG /?PRG1
PRINTI "[Splits left (SPLIT ptr = "
GET SPLIT-STACK,0
PRINTN STACK
PRINTI "), trying again...]
"
JUMP ?PRG1
?CCL28: ADD 1,TMP
PUT SPLIT-STACK,T2,STACK
JUMP ?REP17
?REP2: ZERO? P-RESPONDED /?CND35
SUB 0,NUM
ICALL2 BE-PATIENT,STACK
?CND35: EQUAL? RES,PARSER-RESULT-WON \?CCL39
RETURN PARSER-RESULT
?CCL39: ZERO? RES /TRUE
RFALSE
.FUNCT PARSE-SENTENCE:ANY:1:1,PR,SPLIT-NUM,RES,WCN,CURRENT-TOKEN,OLD-WCN,CAV,OFFS,T2,CURRENT-ACTION,REDUCTION,N,?TMP1
SET 'SPLIT-NUM,-1
GET TLEXV,0 >CURRENT-TOKEN
CATCH >PARSE-SENTENCE-ACTIVATION
ZERO? CURRENT-TOKEN \?CND1
CALL2 UNKNOWN-WORD,TLEXV >CURRENT-TOKEN
ZERO? CURRENT-TOKEN \?CND1
RETURN PARSER-RESULT-DEAD
?CND1: ZERO? P-DBUG /?CND5
PRINTI "[Next token: "
PRINTB CURRENT-TOKEN
PRINTI "; WCN "
GET CURRENT-TOKEN,4
PRINTN STACK
PRINTI "]
"
?CND5: GET CURRENT-TOKEN,4 >WCN
SET 'OLD-WCN,WCN
?PRG7: EQUAL? CURRENT-TOKEN,W?S \?CND9
SUB TLEXV,4
GET STACK,0
EQUAL? STACK,W?APOSTROPHE \?CND9
SET 'OLD-WCN,32
SET 'WCN,OLD-WCN
?CND9: ZERO? WCN \?CCL15
GET CURRENT-TOKEN,3
ZERO? STACK \?CCL18
CALL BUZZER-WORD?,CURRENT-TOKEN,TLEXV
ZERO? STACK /?CND19
MUL P-LEXELEN,P-WORD-NUMBER
ADD STACK,P-LEXSTART
PUT OOPS-TABLE,O-PTR,STACK
RETURN PARSER-RESULT-DEAD
?CND19: SET 'CAV,FALSE-VALUE
JUMP ?CND13
?CCL18: GET CURRENT-TOKEN,3 >CURRENT-TOKEN
GET CURRENT-TOKEN,4 >OLD-WCN
SET 'WCN,OLD-WCN
JUMP ?PRG7
?CCL15: BTST OLD-WCN,32768 /?CCL23
SET 'OFFS,1
JUMP ?CND21
?CCL23: SET 'OFFS,0
?CND21: CALL2 PEEK-PSTACK,STATE-STACK
GET ACTION-TABLE,STACK
GET STACK,0
CALL GET-TERMINAL-ACTION,WCN,STACK,OFFS >CAV
ZERO? CAV /?CND24
BAND WCN,32767 >?TMP1
GET CAV,OFFS
BCOM STACK
BAND ?TMP1,STACK
ZERO? STACK /?CND24
ADD CAV,6
CALL GET-TERMINAL-ACTION,WCN,STACK,OFFS
ZERO? STACK /?CND24
ADD SPLIT-NUM,2 >SPLIT-NUM
ADD SPLIT-NUM,1
GET SPLIT-STACK,0 >T2
GRTR? STACK,T2 \?CCL31
INC 'SPLITS
INC 'T2
LESS? T2,21 /?CND32
ICALL1 P-NO-MEM-ROUTINE
?CND32: PUT SPLIT-STACK,0,T2
PUT SPLIT-STACK,T2,CAV
INC 'T2
LESS? T2,21 /?CND34
ICALL1 P-NO-MEM-ROUTINE
?CND34: PUT SPLIT-STACK,0,T2
BAND OLD-WCN,32768
BOR STACK,WCN
PUT SPLIT-STACK,T2,STACK
ZERO? P-DBUG /?CND24
PRINTI "[New split on a"
PRINTI " word"
PRINTI " (split #"
PRINTN SPLITS
PRINTI ") at depth "
DIV T2,2
PRINTN STACK
PRINTI "; word class: "
PRINTN WCN
PRINTI "; left: "
BAND WCN,32767 >?TMP1
GET CAV,OFFS
BCOM STACK
BAND ?TMP1,STACK
PRINTN STACK
PRINTI ".]
"
JUMP ?CND24
?CCL31: SUB SPLIT-NUM,1
GET SPLIT-STACK+2,STACK >CAV
ZERO? CAV /?CND24
ZERO? P-DBUG /?CND40
PRINTI "[Old split on a word (split #"
PRINTN SPLITS
PRINTI ") at depth "
DIV T2,2
PRINTN STACK
PRINTI "; word class: "
PRINTN WCN
PRINTI "; using: "
?CND40: ZERO? P-DBUG /?CND24
ZERO? CAV /?CCL46
BAND WCN,32767 >?TMP1
GET CAV,OFFS
BAND ?TMP1,STACK
PRINTN STACK
JUMP ?CND44
?CCL46: PRINTN 0
?CND44: PRINTI "]
"
?CND24: ZERO? CAV \?CND47
ZERO? P-DBUG /?CND49
PRINTI "[A parse loses.]
"
?CND49: RETURN PARSER-RESULT-FAILED
?CND47: ZERO? P-DBUG /?CND51
BAND WCN,32767 >?TMP1
GET CAV,OFFS
BCOM STACK
BAND ?TMP1,STACK
ZERO? STACK /?CND51
PRINTI "[Current WCN is "
GET CAV,OFFS
BAND WCN,STACK
PRINTN STACK
PRINTC 93
CRLF
?CND51: GET CAV,OFFS
BAND WCN,STACK >WCN
?CND13: ZERO? CAV /?PST56
GET CAV,2 >CURRENT-ACTION
JUMP ?PRG58
?PST56: SET 'CURRENT-ACTION,0
?PRG58: ZERO? CAV /?CCL62
BAND CURRENT-ACTION,65280
ZERO? STACK /?CCL62
ADD SPLIT-NUM,2 >SPLIT-NUM
ADD SPLIT-NUM,1
GET SPLIT-STACK,0 >T2
GRTR? STACK,T2 \?CCL67
INC 'SPLITS
INC 'T2
LESS? T2,21 /?CND68
ICALL1 P-NO-MEM-ROUTINE
?CND68: PUT SPLIT-STACK,0,T2
GETB CURRENT-ACTION,0
PUT SPLIT-STACK,T2,STACK
INC 'T2
LESS? T2,21 /?CND70
ICALL1 P-NO-MEM-ROUTINE
?CND70: PUT SPLIT-STACK,0,T2
PUT SPLIT-STACK,T2,1
ZERO? P-DBUG /?CND72
PRINTI "[New split on a"
PRINTI "n action"
PRINTI " (split #"
PRINTN SPLITS
PRINTI ") at depth "
DIV T2,2
PRINTN STACK
PRINTI ", "
GETB CURRENT-ACTION,0
PRINTN STACK
PRINTI " cases.]
"
?CND72: GETB CURRENT-ACTION,1 >CURRENT-ACTION
JUMP ?CND65
?CCL67: GET SPLIT-STACK+2,SPLIT-NUM
GETB CURRENT-ACTION,STACK >CURRENT-ACTION
?CND65: ZERO? P-DBUG /?CND60
PRINTI "[Using action "
PRINTN CURRENT-ACTION
PRINTI ".]
"
JUMP ?CND60
?CCL62: ZERO? CAV /?CND60
ZERO? CURRENT-ACTION \?CND60
ZERO? P-DBUG /?CND79
PRINTI "[A parse loses.]
"
?CND79: RETURN PARSER-RESULT-FAILED
?CND60: ZERO? CAV /?CTR82
LESS? CURRENT-ACTION,128 \?CCL83
?CTR82: ZERO? CAV /?CND86
ZERO? P-DBUG /?CND88
PRINTI "[Pushing: "
PRINTB CURRENT-TOKEN
PRINTI "; new state "
PRINTN CURRENT-ACTION
PRINTI "]
"
?CND88: XPUSH CURRENT-TOKEN,DATA-STACK \?CCL92
XPUSH CURRENT-ACTION,STATE-STACK /?CND86
?CCL92: ICALL1 P-NO-MEM-ROUTINE
?CND86: DLESS? 'P-LEN,1 \?CCL97
SET 'CURRENT-TOKEN,W?END.OF.INPUT
ADD 1,P-WORD-NUMBER >P-WORDS-AGAIN
SET 'P-CONT,FALSE-VALUE
SET 'P-LEN,0
JUMP ?CND95
?CCL97: INC 'P-WORD-NUMBER
ADD TLEXV,4 >TLEXV
GET TLEXV,0 >CURRENT-TOKEN
GRTR? TLEXV,OTLEXV \?CND95
SET 'OTLEXV,TLEXV
?CND95: ZERO? CURRENT-TOKEN \?CCL102
CALL2 UNKNOWN-WORD,TLEXV >CURRENT-TOKEN
ZERO? CURRENT-TOKEN \?CND100
RETURN PARSER-RESULT-DEAD
?CCL102: EQUAL? CURRENT-TOKEN,W?THEN,W?!,W?PERIOD /?CCL105
EQUAL? CURRENT-TOKEN,W?? \?CND100
?CCL105: SET 'P-WORDS-AGAIN,P-WORD-NUMBER
DLESS? 'P-LEN,1 /?CCL110
ADD TLEXV,4 >P-CONT
JUMP ?CND100
?CCL110: SET 'P-CONT,FALSE-VALUE
?CND100: GET CURRENT-TOKEN,4 >OLD-WCN
SET 'WCN,OLD-WCN
ZERO? P-DBUG /?PRG7
PRINTI "[Next token: "
PRINTB CURRENT-TOKEN
PRINTI "; WCN "
PRINTN WCN
PRINTI "]
"
JUMP ?PRG7
?CCL83: GRTR? CURRENT-ACTION,128 \?CCL114
SUB CURRENT-ACTION,129
GET REDUCTION-TABLE,STACK >REDUCTION
ZERO? P-DBUG /?CND117
PRINTI "[Reducing "
GET REDUCTION,5
PRINT STACK
CRLF
PRINTI "Args:"
GET REDUCTION,0 >N
?PRG119: DLESS? 'N,0 \?CND121
PRINTI " ..."
?CND117: GET REDUCTION,0 >RES
ZERO? RES /?CND123
FSTACK RES,STATE-STACK
?CND123: SET 'CURRENT-REDUCTION,REDUCTION
SET 'P-RUNNING,TLEXV
GET REDUCTION,1 >?TMP1
GET REDUCTION,0
CALL ?TMP1,STACK >RES
SET 'TLEXV,P-RUNNING
GRTR? TLEXV,OTLEXV \?CND125
SET 'OTLEXV,TLEXV
?CND125: LESS? P-LEN,1 \?CCL129
SET 'CURRENT-TOKEN,W?END.OF.INPUT
GET CURRENT-TOKEN,4 >OLD-WCN
SET 'WCN,OLD-WCN
JUMP ?CND127
?CND121: PRINTC 32
CALL PEEK-PSTACK,DATA-STACK,N
ICALL2 P-P,STACK
JUMP ?PRG119
?CCL129: GET TLEXV,0
EQUAL? CURRENT-TOKEN,STACK /?CND127
GET TLEXV,0 >CURRENT-TOKEN
GET CURRENT-TOKEN,4 >OLD-WCN
SET 'WCN,OLD-WCN
?CND127: SET 'CURRENT-REDUCTION,FALSE-VALUE
ZERO? RES \?CTR132
RETURN PARSER-RESULT-FAILED
?CTR132: XPUSH RES,DATA-STACK /?CND131
ICALL1 P-NO-MEM-ROUTINE
?CND131: CALL2 PEEK-PSTACK,STATE-STACK
GET ACTION-TABLE,STACK >?TMP1
GET REDUCTION,4
CALL GET-NONTERMINAL-ACTION,?TMP1,STACK
XPUSH STACK,STATE-STACK /?CND136
ICALL1 P-NO-MEM-ROUTINE
?CND136: ZERO? P-DBUG /?PRG7
PRINTI " result: "
ICALL2 P-P,RES
PRINTI ", new state "
CALL2 PEEK-PSTACK,STATE-STACK
PRINTN STACK
PRINTI "]
"
JUMP ?PRG7
?CCL114: POP DATA-STACK >PARSER-RESULT
RETURN PARSER-RESULT-WON
.FUNCT GET-TERMINAL-ACTION:ANY:3:3,TYPE,STATE,OFFS,V
ZERO? STATE /FALSE
BAND TYPE,32767 >TYPE
SET 'V,STATE
?PRG4: GET V,0
ZERO? STACK \?CND6
GET V,1
ZERO? STACK /FALSE
?CND6: GET V,OFFS
BAND TYPE,STACK
ZERO? STACK /?CND10
RETURN V
?CND10: ADD V,6 >V
JUMP ?PRG4
.FUNCT GET-NONTERMINAL-ACTION:ANY:2:2,STATE,TYPE,V
GET STATE,1
ZERO? STACK /FALSE
GET STATE,1 >V
?PRG4: GETB V,0
ZERO? STACK /FALSE
GETB V,0
EQUAL? STACK,TYPE \?CND6
GETB V,1
RSTACK
?CND6: ADD V,2 >V
JUMP ?PRG4
.FUNCT BE-PATIENT:ANY:1:1,NUM,LIM
SET 'LIM,16
GETB 0,30
EQUAL? STACK,APPLE-2E,APPLE-2C,APPLE-2GS \?CND1
SET 'LIM,4
?CND1: LESS? NUM,0 \?CCL5
ZERO? P-DBUG /?CND6
PRINTI "[Total: "
SUB 0,NUM
PRINTN STACK
PRINTI " passes.]
"
?CND6: SUB 1,LIM
LESS? NUM,STACK \FALSE
ZERO? P-RESPONDED /FALSE
SET 'P-RESPONDED,0
BUFOUT TRUE-VALUE
PRINTR "]"
?CCL5: MOD NUM,LIM
ZERO? STACK \FALSE
EQUAL? NUM,LIM \?CCL17
SET 'P-RESPONDED,LIM
PRINTI "[Please be patient..."
JUMP ?CND15
?CCL17: ZERO? P-RESPONDED /?CND15
PRINTC 46
?CND15: BUFOUT FALSE-VALUE
RTRUE
.FUNCT MAIN-LOOP:ANY:0:0,X
?PRG1: CALL1 MAIN-LOOP-1 >X
JUMP ?PRG1
.FUNCT MAIN-LOOP-1:ANY:0:0,ICNT,OCNT,NUM,OBJ,V,OBJ1,NP,NP1,XX,CNT,TMP
CALL1 PARSER >P-WON
ZERO? P-WON /?CCL3
?PRG4: GET PARSE-RESULT,4 >PRSA
EQUAL? PRSA,V?UNDO \?CCL8
SET 'PRSS,FALSE-VALUE
SET 'PRSQ,FALSE-VALUE
CALL2 PERFORM,PRSA
RSTACK
?CCL8: ISAVE >P-CAN-UNDO
EQUAL? P-CAN-UNDO,2 \?CND6
EQUAL? PRSA,V?SAVE \?CCL13
ICALL1 CANT-UNDO
RFALSE
?CCL13: SET 'P-CONT,-1
ICALL1 V-$REFRESH
RFALSE
?CND6: GET PARSE-RESULT,5 >P-PRSO
GET PARSE-RESULT,6 >P-PRSI
ZERO? P-PRSO /?CCL17
GET P-PRSO,3
EQUAL? INTDIR,STACK \?CCL17
GET P-PRSO,4
GET STACK,2
GETB STACK,6 >P-DIRECTION
JUMP ?CND15
?CCL17: ZERO? P-PRSI /?CND15
GET P-PRSI,3
EQUAL? INTDIR,STACK \?CND15
GET P-PRSI,4
GET STACK,2
GETB STACK,6 >P-DIRECTION
?CND15: GET PARSE-RESULT,1 >P-PRSA-WORD
SET 'CLOCK-WAIT,FALSE-VALUE
SET 'ICNT,0
SET 'OCNT,0
ZERO? P-PRSI /?CND23
GET P-PRSI,1 >ICNT
ZERO? ICNT /?CND23
SET 'P-MULT,ICNT
?CND23: ZERO? P-PRSO /?CND27
GET P-PRSO,1 >OCNT
ZERO? OCNT /?CND27
SET 'P-MULT,OCNT
?CND27: ZERO? OCNT \?CCL33
ZERO? ICNT /?CND31
?CCL33: EQUAL? PRSA,V?WALK /?CND31
ZERO? P-IT-OBJECT /?CND31
ZERO? ICNT /?CND39
ICALL MAIN-LOOP-IT,ICNT,P-PRSI
?CND39: ZERO? OCNT /?CND31
ICALL MAIN-LOOP-IT,OCNT,P-PRSO
?CND31: ZERO? OCNT \?CCL45
SET 'NUM,OCNT
JUMP ?CND43
?CCL45: GRTR? OCNT,1 \?CCL47
ZERO? ICNT \?CCL50
SET 'OBJ,FALSE-VALUE
JUMP ?CND48
?CCL50: GET P-PRSI,3 >OBJ
GET P-PRSI,4 >NP
?CND48: SET 'NUM,OCNT
JUMP ?CND43
?CCL47: GRTR? ICNT,1 \?CCL54
GET P-PRSO,3 >OBJ
GET P-PRSI,4 >NP
SET 'NUM,ICNT
JUMP ?CND43
?CCL54: SET 'NUM,1
?CND43: ZERO? OBJ \?CND57
EQUAL? ICNT,1 \?CND57
GET P-PRSI,3 >OBJ
GET P-PRSI,4 >NP
?CND57: GET PARSE-RESULT,12 >V
ZERO? V /?CND63
GET V,1
LESS? 1,STACK \?CND63
GET V,2
ZERO? STACK \?CND63
PUT V,2,1
GET V,3
PRINTD STACK
PRINTI ":
"
?CND63: GET PARSE-RESULT,15 >V