-
Notifications
You must be signed in to change notification settings - Fork 0
/
INFSPR.h
1774 lines (1474 loc) · 65.7 KB
/
INFSPR.h
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
! =====================================================================
! INFSP (Spanish Inform Library)
! =====================================================================
! Author: INFSP Task Team
! Version: 0.9
! Released: 21- Enero - 2009
! Serial Number: 901.21
! Note: For use with Inform 6. (Tested with Inform compiler
! version 6.31 and Inform library 6/11).
! Description: "An Inform library to write Interactive Fiction in
! Spanish. INFSPR.h: Parsers Replacements/Hack."
! =====================================================================
Message "Incluyendo INFSPR [INFSP 0.9]";
! Constant INFSPR_adv; !descomentar esta linea si se quiere tener los mensajes de
! reemplazo de rutinas hackeadas al compilar
! ------------------------------------
! Parser Replace Section
! ------------------------------------
! Rutinas Hackeadas:
! DictionaryLookup BUG
! BestGuess SP PATCH
! Identical SP PATCH
! PrefaceByArticle SP PATCH
! TryGivenObject SP PATCH
! NounDomain SP PATCH
! Indefart SP PATCH
! CInDefArt SP PATCH
! Parser__parse SP PATCH
! ReviseMulti SP PATCH
! ChangePlayer SP PATCH
! Definicion de bufferaux y parseraux, usados en DictionaryLookup [001115]
#ifdef TARGET_ZCODE;
Array bufferaux -> 123;
Array parseaux buffer 63;
#ifnot; ! TARGET_GLULX
Array bufferaux buffer INPUT_BUFFER_LEN;
Array parseaux --> PARSE_BUFFER_LEN;
#endif; ! TARGET_
! Tremendo bug corregido. Antes usaba el buffer buf2, el cual usa
! tambien el parser para leer commandos incompletos del estilo de "¿a
! cual te refieres exactamente?"
! Este bug estaba en la libreria original, pero nunca aparecia porque
! apenas se usa DictionaryLookup. En cambio InformATE lo usa para
! comprobar si quitando la R a un verbo se obtiene una palabra válida.
!
! [Gracias a Presi por detectarlo]
!
#ifdef INFSPR_adv; Message " Incluyendo reemplazo DictionaryLookup"; #endif;
[ DictionaryLookup texto longitud
i;
! copiar texto a bufferaux (copiado especial)
for (i=0:i<longitud:i++) bufferaux->(WORDSIZE+i) = texto->i;
! completar correctamente cabeceras de los buffers
! para la rutina Tokenise.
#ifdef TARGET_ZCODE;
bufferaux->1 = longitud;
! bufferaux->0 = longitud;
bufferaux->0 = 120;
parseaux-> 0 = 1;
#ifnot; ! TARGET_GLULX
bufferaux-->0 = longitud;
#endif; ! TARGET_
if (parser_trace>=9) { ! infsp debug
print " DictionaryLookup: texto a procesar: |";
ImprimeTodoElBuffer(bufferaux);
print "|^";
}
Tokenise__(bufferaux,parseaux); ! procesar texto de bufferaux, el resultado está en parseaux-->1
return parseaux-->1; ! retornar address del token encontrado (-1 si falla)
];
! ###############################################################################
! ----------------------------------------------------------------------------
! BestGuess makes the best guess it can out of the match list, assuming
! that everything in the match list is textually as good as everything else;
! however it ignores items marked as -1, and so marks anything it chooses.
! It returns -1 if there are no possible choices.
! ----------------------------------------------------------------------------
! Modificada en la revisión [020415] de modo que si hay varios objetos con la
! mayor puntuación, se elija uno de ellos al azar, en vez de elegir siempre al
! primero. Solo usado en I6. I7 usa uno mas elaborado.
#ifdef INFSPR_adv;Message " Incluyendo reemplazo BestGuess"; #endif;
[ BestGuess earliest its_score best i mejores aleat j;
earliest=0; best=-1; mejores=0;
for (i=0:i<number_matched:i++)
{ if (match_list-->i >= 0)
{ its_score=match_scores-->i;
if (its_score>best) {
best=its_score;
earliest=i;
mejores=1;
}
else if (its_score == best)
mejores++;
}
}
if (mejores > 1) {
aleat = random (mejores);
for (i = 0, j = 0: i < number_matched: i++)
! Antes se initializaba j = 1 (bug corregido en [020423])
{
if (match_list-->i >= 0)
{
its_score = match_scores-->i;
if (its_score == best)
j++;
if (j == aleat)
{
earliest = i;
break;
}
}
}
}
#ifdef DEBUG;
if (parser_trace>=4)
{
if (best < 0) print " Best guess ran out of choices^";
else print " Best guess ", (the) match_list-->earliest, " (", match_list-->earliest, ")^";
}
#endif;
if (best<0) return -1;
i=match_list-->earliest;
match_list-->earliest=-1;
bestguess_score = best;
return i;
];
! ##############################################################################
! ----------------------------------------------------------------------------
! Identical decides whether or not two objects can be distinguished from
! each other by anything the player can type. If not, it returns true.
! ----------------------------------------------------------------------------
! Modificado en la versión [020423] para comparar además de name, las otras
! propiedades de la librería española InformATE! que sirven también para nombrar
! los objetos: name_f, name_fp, name_mp y adjectives. Si se programan bien
! los juegos, con esto se puede solucionar el problema de la desambiguación.
#ifdef INFSPR_adv;Message " Incluyendo reemplazo Identical"; #endif;
[ Identical o1 o2 p1 p2 n1 n2 i j flag pasada;
if (o1==o2) rtrue; ! This should never happen, but to be on the safe side
if (o1==0 || o2==0) rfalse; ! Yesmilarly
if (parent(o1)==compass || parent(o2)==compass) rfalse; ! Saves time
! What complicates things is that o1 or o2 might have a parsing routine,
! so the parser can't know from here whether they are or aren't the same.
! If they have different parsing routines, we simply assume they're
! different. If they have the same routine (which they probably got from
! a class definition) then the decision process is as follows:
!
! the routine is called (with self being o1, not that it matters)
! with noun and second being set to o1 and o2, and action being set
! to the fake action TheSame. If it returns -1, they are found
! identical; if -2, different; and if >=0, then the usual method
! is used instead.
if (o1.parse_name~=0 || o2.parse_name~=0) !ambos tienen propiedad parser_name?
{ if (o1.parse_name ~= o2.parse_name) rfalse;
parser_action=##TheSame; parser_one=o1; parser_two=o2;
j=wn; i=RunRoutines(o1,parse_name); wn=j;
if (i==-1) rtrue; if (i==-2) rfalse;
}
! This is the default algorithm: do they have the same words in their
! "name" (i.e. property no. 1) properties. (Note that the following allows
! for repeated words and words in different orders.)
! p1 = o1.&1; n1 = (o1.#1)/WORDSIZE; ! Para mí, referirse a una propiedad
! p2 = o2.&1; n2 = (o2.#1)/WORDSIZE; ! con un número es una burrada
! ¿TODO? OJO: Este método compara si cada una de las propiedades de names y
! demás a buscar tiene las mismas palabras, pero entre ellas mismas (esto es,
! por ejemplo entre adjetivos de o1 y de o2), no entre sí (como, por ejemplo,
! entre las de name de o1 y adjetivos de o2).
!
! Posiblemente lo ideal fuera mirar si todas las palabras de todas estas
! propiedades de o1 están en las propiedades de o2 y viceversa.
! pasada almacenará el número de pasada por el que se va, para saber si toca
! comparar name(1), adjetivos(2), name_f(3), name_mp(4) o name_fp(5)
for (pasada = 1: pasada < 6: pasada++) {
switch (pasada) {
1:
p1 = o1.&name; n1 = (o1.#name)/WORDSIZE;
p2 = o2.&name; n2 = (o2.#name)/WORDSIZE;
2:
p1 = o1.&adjectives; n1 = (o1.#adjectives)/WORDSIZE;
p2 = o2.&adjectives; n2 = (o2.#adjectives)/WORDSIZE;
3:
p1 = o1.&name_f; n1 = (o1.#name_f)/WORDSIZE;
p2 = o2.&name_f; n2 = (o2.#name_f)/WORDSIZE;
4:
p1 = o1.&name_mp; n1 = (o1.#name_mp)/WORDSIZE;
p2 = o2.&name_mp; n2 = (o2.#name_mp)/WORDSIZE;
5:
p1 = o1.&name_fp; n1 = (o1.#name_fp)/WORDSIZE;
p2 = o2.&name_fp; n2 = (o2.#name_fp)/WORDSIZE;
} ! del switch
! for (i=0:i<n1:i++) { print (address) p1-->i, " "; } new_line;
! for (i=0:i<n2:i++) { print (address) p2-->i, " "; } new_line;
for (i = 0: i < n1: i++)
{
flag = 0;
for (j = 0: j < n2: j++)
if (p1-->i == p2-->j)
flag = 1;
if (flag == 0) rfalse;
}
for (j = 0: j < n2: j++)
{
flag = 0;
for (i = 0: i < n1: i++)
if (p1-->i == p2-->j)
flag = 1;
if (flag == 0) rfalse;
}
} ! del for
! print "Which are identical!^";
rtrue;
];
! ##############################################################################
! PrefaceByArticle actualizado a la 6/11, con hackeos de genero (a partir de INFSP0.8f)
#ifdef INFSPR_adv;Message " Incluyendo reemplazo PrefaceByArticle"; #endif;
[ PrefaceByArticle o acode pluralise capitalise i artform findout artval;
if (o provides articles) {
artval=(o.&articles)-->(acode+short_name_case*LanguageCases);
if (artval) { ! infsp hack para admitir valor 0 en slot de 'articles' property.
if (capitalise)
print (Cap) artval, " ";
else
print (string) artval, " ";
}
if (pluralise) return;
print (PSN__) o; return;
}
if (o provides gender){ ![infsp]'gender'(informATE exclusive) es el genero de short_name del objeto
i=o.gender;
if (i==1) ! infsp : esto es una chanchada, pero al cambiarse los valores de 'gender' por lo de la
i=0; ! compatibilidad con I7 (donde no puede ponerse gender = 0), quedo desfasado el array
else if (i==2) ! LanguageGNAsToArticles. TODO: corregir el array y testear estabilidad.
i=1; !
else if (i==4 or 5) ! Todos estos los incluyo yo (Sothoth)...
i=3; ! para ajustar el array...
else if (i==6) ! al nuevo valor...
i=4; ! de G_PLURAL
}else{ i = GetGNAOfObject(o);}
! print "^pluralise:",pluralise; ![infsp] debug
! print "^1 valor de i:",i; ![infsp] debug
! [infsp]: para q funcione con (el_), se agrego '>0' para el correcto funcionamiento (sino al final imprime el nombre de objeto cuando yo solo quiero imprimir su articulo)
if (pluralise>0) { ![INFSP] ej, en ListMiscellany 19,[TODO] esto podria resolverse como los italianos
if (i < 3 || (i >= 6 && i < 9)) i = i + 3;
}
! print "^2 valor de i:",i; ![infsp] debug
i = LanguageGNAsToArticles-->i;
! print "^3 valor de i:",i," ";! infsp debug
artform = LanguageArticles
+ 3*WORDSIZE*LanguageContractionForms*(short_name_case + i*LanguageCases);
#Iftrue (LanguageContractionForms == 2);
if (artform-->acode ~= artform-->(acode+3)) findout = true;
#Endif; ! LanguageContractionForms
#Iftrue (LanguageContractionForms == 3);
if (artform-->acode ~= artform-->(acode+3)) findout = true;
if (artform-->(acode+3) ~= artform-->(acode+6)) findout = true;
#Endif; ! LanguageContractionForms
#Iftrue (LanguageContractionForms == 4);
if (artform-->acode ~= artform-->(acode+3)) findout = true;
if (artform-->(acode+3) ~= artform-->(acode+6)) findout = true;
if (artform-->(acode+6) ~= artform-->(acode+9)) findout = true;
#Endif; ! LanguageContractionForms
#Iftrue (LanguageContractionForms > 4);
findout = true;
#Endif; ! LanguageContractionForms
#Ifdef TARGET_ZCODE;
if (standard_interpreter ~= 0 && findout) {
StorageForShortName-->0 = 160;
@output_stream 3 StorageForShortName;
if (pluralise) print (number) pluralise; else print (PSN__) o;
@output_stream -3;
acode = acode + 3*LanguageContraction(StorageForShortName + 2);
}
#Ifnot; ! TARGET_GLULX
if (findout) {
if (pluralise)
PrintAnyToArray(StorageForShortName, 160, EnglishNumber, pluralise);
else
PrintAnyToArray(StorageForShortName, 160, PSN__, o);
acode = acode + 3*LanguageContraction(StorageForShortName);
}
#Endif; ! TARGET_
Cap (artform-->acode, ~~capitalise); ! print article
if (pluralise) return;
print (PSN__) o;!imprime el nombre del objeto
];
! #############################################################################
! ----------------------------------------------------------------------------
! TryGivenObject tries to match as many words as possible in what has been
! typed to the given object, obj. If it manages any words matched at all,
! it calls MakeMatch to say so, then returns the number of words (or 1
! if it was a match because of inadequate input).
! ----------------------------------------------------------------------------
! INFSP: Se resetea a 'nombreusado' - relacionado con el genero del objeto.
#ifdef INFSPR_adv;Message " Incluyendo reemplazo TryGivenObject"; #endif;
[ TryGivenObject obj nomatch threshold k w j;
#Ifdef DEBUG;
if (parser_trace >= 5) print " Trying ", (the) obj, " (", obj, ") at word ", wn, "^";
#Endif; ! DEBUG
if (nomatch && obj == 0) return 0;
! if (nomatch) print "*** TryGivenObject *** on ", (the) obj, " at wn = ", wn, "^";
dict_flags_of_noun = 0;
! If input has run out then always match, with only quality 0 (this saves
! time).
if (wn > num_words) {
if (nomatch) return 0;
if (indef_mode ~= 0)
dict_flags_of_noun = $$01110000; ! Reject "plural" bit
MakeMatch(obj,0);
give obj ~nombreusado; ![INFSP] hack: evitar que un objeto no mencionado en este turno sea elejido (Related: ChooseObjects/ElijeObjetos)
#Ifdef DEBUG;
if (parser_trace >= 5) print " Matched (0)^";
#Endif; ! DEBUG
return 1;
}
! Ask the object to parse itself if necessary, sitting up and taking notice
! if it says the plural was used:
if (obj.parse_name~=0) {
! print " <obj ",(the) obj," has parse_name>^";! infsp debug
parser_action = NULL; j=wn;
k = RunRoutines(obj,parse_name);
! print " k value-->",k ,"^";! infsp debug
if (k > 0) {
give obj nombreusado; ! infsp hack, I7: cuando coinciden en el parse_name
! sino no pueden usarse adjetivos para desambiguar
wn=j+k;
.MMbyPN;
if (parser_action == ##PluralFound)
dict_flags_of_noun = dict_flags_of_noun | 4;
if (dict_flags_of_noun & 4) {
if (~~allow_plurals) k = 0;
else {
if (indef_mode == 0) {
indef_mode = 1; indef_type = 0; indef_wanted = 0;
}
indef_type = indef_type | PLURAL_BIT;
if (indef_wanted == 0) indef_wanted = 100;
}
}
#Ifdef DEBUG;
if (parser_trace >= 5) print " Matched (", k, ")^";
#Endif; ! DEBUG
if (nomatch == false) MakeMatch(obj,k);
return k;
}
if (k == 0) jump NoWordsMatch;
wn = j;
}
! The default algorithm is simply to count up how many words pass the
! Refers test:
parser_action = NULL;
w = NounWord();
if (w == 1 && player == obj) { k=1; jump MMbyPN; }
if (w >= 2 && w < 128 && (LanguagePronouns-->w == obj)) { k = 1; jump MMbyPN; }
j=--wn;
threshold = ParseNoun(obj);
#Ifdef DEBUG;
if (threshold >= 0 && parser_trace >= 5) print " ParseNoun returned ", threshold, "^";
#Endif; ! DEBUG
if (threshold < 0) wn++;
if (threshold > 0) { k = threshold; jump MMbyPN; }
if (threshold == 0 || Refers(obj,wn-1) == 0) {
.NoWordsMatch;
if (indef_mode ~= 0) {
k = 0; parser_action = NULL;
jump MMbyPN;
}
rfalse;
}
if (threshold < 0) {
threshold = 1;
dict_flags_of_noun = (w->#dict_par1) & $$01110100;
w = NextWord();
while (Refers(obj, wn-1)) {
threshold++;
if (w)
dict_flags_of_noun = dict_flags_of_noun | ((w->#dict_par1) & $$01110100);
w = NextWord();
}
}
k = threshold;
jump MMbyPN;
];
! ###########################################################################################
! Esta version de NounDomain para I6 utiliza ImprimirListaDudosos (indirectamente via Mensajes 45,46)
! que es mas eficiente al listar solo los objetos realmente relevantes (uso de adjetivos y demas)
#ifdef INFSPR_adv;Message " Incluyendo reemplazo NounDomain"; #endif;
[ NounDomain domain1 domain2 context first_word i j k l
answer_words marker;
marker = marker; ! [infsp] para evitar el warning de variable no usada.
! no se usa en I6 pero por ahora sí en I7
#Ifdef DEBUG;
if (parser_trace >= 4) {
print " [NounDomain called at word ", wn, "^";
print " ";
if (indef_mode) {
print "seeking indefinite object: ";
if (indef_type & OTHER_BIT) print "other ";
if (indef_type & MY_BIT) print "my ";
if (indef_type & THAT_BIT) print "that ";
if (indef_type & PLURAL_BIT) print "plural ";
if (indef_type & LIT_BIT) print "lit ";
if (indef_type & UNLIT_BIT) print "unlit ";
if (indef_owner ~= 0) print "owner:", (name) indef_owner;
new_line;
print " number wanted: ";
if (indef_wanted == 100) print "all"; else print indef_wanted;
new_line;
print " most likely GNAs of names: ", indef_cases, "^";
}
else print "seeking definite object^";
}
#Endif; ! DEBUG
match_length = 0; number_matched = 0; match_from = wn; placed_in_flag = 0;
SearchScope(domain1, domain2, context);
#Ifdef DEBUG;
if (parser_trace >= 4) print " [ND made ", number_matched, " matches]^";
#Endif; ! DEBUG
wn = match_from+match_length;
! If nothing worked at all, leave with the word marker skipped past the
! first unmatched word...
if (number_matched == 0) { wn++; rfalse; }
! Suppose that there really were some words being parsed (i.e., we did
! not just infer). If so, and if there was only one match, it must be
! right and we return it...
if (match_from <= num_words) {
if (number_matched == 1) {
i=match_list-->0;
return i;
}
! ...now suppose that there was more typing to come, i.e. suppose that
! the user entered something beyond this noun. If nothing ought to follow,
! then there must be a mistake, (unless what does follow is just a full
! stop, and or comma)
if (wn <= num_words) {
i = NextWord(); wn--;
if (i ~= AND1__WD or AND2__WD or AND3__WD or comma_word
or THEN1__WD or THEN2__WD or THEN3__WD
or BUT1__WD or BUT2__WD or BUT3__WD) {
if (lookahead == ENDIT_TOKEN) rfalse;
}
}
}
! Now look for a good choice, if there's more than one choice...
number_of_classes = 0;
if (number_matched == 1) i = match_list-->0;
if (number_matched > 1) {
i = Adjudicate(context);
if (i == -1) rfalse;
if (i == 1) rtrue; ! Adjudicate has made a multiple
! object, and we pass it on
}
! If i is non-zero here, one of two things is happening: either
! (a) an inference has been successfully made that object i is
! the intended one from the user's specification, or
! (b) the user finished typing some time ago, but we've decided
! on i because it's the only possible choice.
! In either case we have to keep the pattern up to date,
! note that an inference has been made and return.
! (Except, we don't note which of a pile of identical objects.)
if (i ~= 0) {
if (dont_infer) return i;
if (inferfrom == 0) inferfrom=pcount;
pattern-->pcount = i;
return i;
}
! If we get here, there was no obvious choice of object to make. If in
! fact we've already gone past the end of the player's typing (which
! means the match list must contain every object in scope, regardless
! of its name), then it's foolish to give an enormous list to choose
! from - instead we go and ask a more suitable question...
if (match_from > num_words) jump Incomplete;
! Now we print up the question, using the equivalence classes as worked
! out by Adjudicate() so as not to repeat ourselves on plural objects...
if (context==CREATURE_TOKEN) L__M(##Miscellany, 45);
else L__M(##Miscellany, 46);
L__M(##Miscellany, 57); !imprime "?^"
! ...and get an answer:
.WhichOne;
#Ifdef TARGET_ZCODE;
for (i=2 : i<INPUT_BUFFER_LEN : i++) buffer2->i = ' ';
#Endif; ! TARGET_ZCODE
answer_words=Keyboard(buffer2, parse2);
! Conveniently, parse2-->1 is the first word in both ZCODE and GLULX.
first_word = (parse2-->1);
! Take care of "all", because that does something too clever here to do
! later on:
if (first_word == ALL1__WD or ALL2__WD or ALL3__WD or ALL4__WD or ALL5__WD) {
if (context == MULTI_TOKEN or MULTIHELD_TOKEN or MULTIEXCEPT_TOKEN or MULTIINSIDE_TOKEN) {
l = multiple_object-->0;
for (i=0 : i<number_matched && l+i<63 : i++) {
k = match_list-->i;
multiple_object-->(i+1+l) = k;
}
multiple_object-->0 = i+l;
rtrue;
}
L__M(##Miscellany, 47);
jump WhichOne;
}
! If the first word of the reply can be interpreted as a verb, then
! assume that the player has ignored the question and given a new
! command altogether.
! (This is one time when it's convenient that the directions are
! not themselves verbs - thus, "north" as a reply to "Which, the north
! or south door" is not treated as a fresh command but as an answer.)
#Ifdef LanguageIsVerb;
if (first_word == 0) {
! print " ND:LanguageIsVerb: WhichOne section^"; ! infsp debug
j = wn; first_word = LanguageIsVerb(buffer2, parse2, 1); wn = j;
}
#Endif; ! LanguageIsVerb
if (first_word ~= 0) {
j = first_word->#dict_par1;
if ((0 ~= j&1) && ~~LanguageVerbMayBeName(first_word)) {
if (parser_trace>=9) { ! [INFSP] for debugging proposes
print "Copiando buffer2: |";
ImprimeTodoElBuffer(buffer2);
print "|^ en buffer: |";
ImprimeTodoElBuffer(buffer);
print "|^";
}
CopyBuffer(buffer, buffer2);
jump RECONSTRUCT_INPUT;
}
}
! Now we insert the answer into the original typed command, as
! words additionally describing the same object
! (eg, > take red button
! Which one, ...
! > music
! becomes "take music red button". The parser will thus have three
! words to work from next time, not two.)
#Ifdef TARGET_ZCODE;
k = WordAddress(match_from) - buffer; l=buffer2->1+1;
for (j=buffer + buffer->0 - 1 : j>=buffer+k+l : j--) j->0 = 0->(j-l);
for (i=0 : i<l : i++) buffer->(k+i) = buffer2->(2+i);
buffer->(k+l-1) = ' ';
buffer->1 = buffer->1 + l;
if (buffer->1 >= (buffer->0 - 1)) buffer->1 = buffer->0;
#Ifnot; ! TARGET_GLULX
k = WordAddress(match_from) - buffer;
l = (buffer2-->0) + 1;
for (j=buffer+INPUT_BUFFER_LEN-1 : j>=buffer+k+l : j--) j->0 = j->(-l);
for (i=0 : i<l : i++) buffer->(k+i) = buffer2->(WORDSIZE+i);
buffer->(k+l-1) = ' ';
buffer-->0 = buffer-->0 + l;
if (buffer-->0 > (INPUT_BUFFER_LEN-WORDSIZE)) buffer-->0 = (INPUT_BUFFER_LEN-WORDSIZE);
#Endif; ! TARGET_
! Having reconstructed the input, we warn the parser accordingly
! and get out.
.RECONSTRUCT_INPUT;
return REPARSE_CODE;
! Now we come to the question asked when the input has run out
! and can't easily be guessed (eg, the player typed "take" and there
! were plenty of things which might have been meant).
.Incomplete;
if (context == CREATURE_TOKEN) L__M(##Miscellany, 48);
else L__M(##Miscellany, 49);
#Ifdef TARGET_ZCODE;
for (i=2 : i<INPUT_BUFFER_LEN : i++) buffer2->i=' ';
#Endif; ! TARGET_ZCODE
answer_words = Keyboard(buffer2, parse2);
first_word=(parse2-->1);
#Ifdef LanguageIsVerb;
if (first_word==0) {
! print " ND:LanguageIsVerb: Incomplete section^"; ! infsp debug
j = wn; first_word=LanguageIsVerb(buffer2, parse2, 1); wn = j;
}
#Endif; ! LanguageIsVerb
! Once again, if the reply looks like a command, give it to the
! parser to get on with and forget about the question...
if (first_word ~= 0) {
j = first_word->#dict_par1;
if (0 ~= j&1) {
CopyBuffer(buffer, buffer2);
return REPARSE_CODE;
}
}
! ...but if we have a genuine answer, then:
!
! (1) we must glue in text suitable for anything that's been inferred.
if (inferfrom ~= 0) {
for (j=inferfrom : j<pcount : j++) {
if (pattern-->j == PATTERN_NULL) continue;
#Ifdef TARGET_ZCODE;
i = 2+buffer->1; (buffer->1)++; buffer->(i++) = ' ';
#Ifnot; ! TARGET_GLULX
i = WORDSIZE + buffer-->0;
(buffer-->0)++; buffer->(i++) = ' ';
#Endif; ! TARGET_
#Ifdef DEBUG;
if (parser_trace >= 5) print "[Gluing in inference with pattern code ", pattern-->j, "]^";
#Endif; ! DEBUG
! Conveniently, parse2-->1 is the first word in both ZCODE and GLULX.
parse2-->1 = 0;
! An inferred object. Best we can do is glue in a pronoun.
! (This is imperfect, but it's very seldom needed anyway.)
if (pattern-->j >= 2 && pattern-->j < REPARSE_CODE) {
PronounNotice(pattern-->j);
for (k=1 : k<=LanguagePronouns-->0 : k=k+3)
if (pattern-->j == LanguagePronouns-->(k+2)) {
parse2-->1 = LanguagePronouns-->k;
#Ifdef DEBUG;
if (parser_trace >= 5) print "[Using pronoun '", (address) parse2-->1, "']^";
#Endif; ! DEBUG
break;
}
}
else {
! An inferred preposition.
parse2-->1 = No__Dword(pattern-->j - REPARSE_CODE);
#Ifdef DEBUG;
if (parser_trace >= 5) print "[Using preposition '", (address) parse2-->1, "']^";
#Endif; ! DEBUG
}
! parse2-->1 now holds the dictionary address of the word to glue in.
if (parse2-->1 ~= 0) {
k = buffer + i;
#Ifdef TARGET_ZCODE;
@output_stream 3 k;
print (address) parse2-->1;
@output_stream -3;
k = k-->0;
for (l=i : l<i+k : l++) buffer->l = buffer->(l+2);
i = i + k; buffer->1 = i-2;
#Ifnot; ! TARGET_GLULX
k = PrintAnyToArray(buffer+i, INPUT_BUFFER_LEN-i, parse2-->1);
i = i + k; buffer-->0 = i - WORDSIZE;
#Endif; ! TARGET_
}
}
}
! (2) we must glue the newly-typed text onto the end.
#Ifdef TARGET_ZCODE;
i = 2+buffer->1; (buffer->1)++; buffer->(i++) = ' ';
for (j=0 : j<buffer2->1 : i++,j++) {
buffer->i = buffer2->(j+2);
(buffer->1)++;
if (buffer->1 == INPUT_BUFFER_LEN) break;
}
#Ifnot; ! TARGET_GLULX
i = WORDSIZE + buffer-->0;
(buffer-->0)++; buffer->(i++) = ' ';
for (j=0 : j<buffer2-->0 : i++,j++) {
buffer->i = buffer2->(j+WORDSIZE);
(buffer-->0)++;
if (buffer-->0 == INPUT_BUFFER_LEN) break;
}
#Endif; ! TARGET_
! (3) we fill up the buffer with spaces, which is unnecessary, but may
! help incorrectly-written interpreters to cope.
#Ifdef TARGET_ZCODE;
for (: i<INPUT_BUFFER_LEN : i++) buffer->i = ' ';
#Endif; ! TARGET_ZCODE
return REPARSE_CODE;
]; ! end of NounDomain
! #############################################################################
! [infsp] Indefart: se agregó el "a " en caso de nombre propio " a Mamá"
#ifdef INFSPR_adv;Message " Incluyendo reemplazo Indefart"; #endif;
[ Indefart o i; ! funcion (a)
if (o == 0) { print (string) NOTHING__TX; rtrue; }
i = indef_mode; indef_mode = true;
if (o has proper) { indef_mode = NULL; print "a ",(PSN__) o; indef_mode = i; return; }
if (o provides article) {
PrintOrRun(o, article, 1); print " ", (PSN__) o; indef_mode = i;
return;
}
PrefaceByArticle(o, 2); indef_mode = i;
];
#ifdef INFSPR_adv;Message " Incluyendo reemplazo CInDefArt"; #endif;
[ CInDefArt o i;
i = indef_mode; indef_mode = true;
if (o has proper) { indef_mode = NULL; print "a ",(PSN__) o; indef_mode = i; return; }
if (o provides article) {
PrintCapitalised(o, article, 1); print " ", (PSN__) o; indef_mode = i;
return;
}
PrefaceByArticle(o, 2, 0, 1); indef_mode = i;
];
! #############################################################################
#ifdef INFSPR_adv;Message " Incluyendo reemplazo Parser__parse"; #endif;
[ Parser__parse results syntax line num_lines line_address i j k
token l m;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! A: Get the input, do "oops" and "again"
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Firstly, in "not held" mode, we still have a command left over from last
! time (eg, the user typed "eat biscuit", which was parsed as "take biscuit"
! last time, with "eat biscuit" tucked away until now). So we return that.
if (notheld_mode == 1) {
for (i=0 : i<8 : i++) results-->i = kept_results-->i;
notheld_mode = 0;
rtrue;
}
if (held_back_mode == 1) {
held_back_mode = 0;
Tokenise__(buffer, parse);
jump ReParse;
}
.ReType;
Keyboard(buffer,parse);
.ReParse;
parser_inflection = name;
! Initially assume the command is aimed at the player, and the verb
! is the first word
#Ifdef TARGET_ZCODE;
num_words = parse->1;
#Ifnot; ! TARGET_GLULX
num_words = parse-->0;
#Endif; ! TARGET_
wn = 1;
#Ifdef LanguageToInformese;
LanguageToInformese();
#IfV5;
! Re-tokenise:
Tokenise__(buffer,parse);
#Endif; ! V5
#Endif; ! LanguageToInformese
BeforeParsing();
#Ifdef TARGET_ZCODE;
num_words = parse->1;
#Ifnot; ! TARGET_GLULX
num_words = parse-->0;
#Endif; ! TARGET_
k=0;
#Ifdef DEBUG;
if (parser_trace >= 2) {
print "[ ";
for (i=0 : i<num_words : i++) {
#Ifdef TARGET_ZCODE;
j = parse-->(i*2 + 1);
#Ifnot; ! TARGET_GLULX
j = parse-->(i*3 + 1);
#Endif; ! TARGET_
k = WordAddress(i+1);
l = WordLength(i+1);
print "~"; for (m=0 : m<l : m++) print (char) k->m; print "~ ";
if (j == 0) print "?";
else {
#Ifdef TARGET_ZCODE;
if (UnsignedCompare(j, HDR_DICTIONARY-->0) >= 0 &&
UnsignedCompare(j, HDR_HIGHMEMORY-->0) < 0)
print (address) j;
else print j;
#Ifnot; ! TARGET_GLULX
if (j->0 == $60) print (address) j;
else print j;
#Endif; ! TARGET_
}
if (i ~= num_words-1) print " / ";
}
print " ]^";
}
#Endif; ! DEBUG
verb_wordnum = 1;
actor = player;
actors_location = ScopeCeiling(player);
usual_grammar_after = 0;
.AlmostReParse;
scope_token = 0;
action_to_be = NULL;
! Begin from what we currently think is the verb word
.BeginCommand;
wn = verb_wordnum;
verb_word = NextWordStopped();
! If there's no input here, we must have something like "person,".
if (verb_word == -1) {
best_etype = STUCK_PE;
jump GiveError;
}
! Now try for "again" or "g", which are special cases: don't allow "again" if nothing
! has previously been typed; simply copy the previous text across
if (verb_word == AGAIN2__WD or AGAIN3__WD) verb_word = AGAIN1__WD;
if (verb_word == AGAIN1__WD) {
if (actor ~= player) {
L__M(##Miscellany, 20);
jump ReType;
}
#Ifdef TARGET_ZCODE;
if (buffer3->1 == 0) {
L__M(##Miscellany, 21);
jump ReType;
}
#Ifnot; ! TARGET_GLULX
if (buffer3-->0 == 0) {
L__M(##Miscellany, 21);
jump ReType;
}
#Endif; ! TARGET_
if (WordAddress(verb_wordnum) == buffer + WORDSIZE) { ! not held back
! splice rest of buffer onto end of buffer3
#Ifdef TARGET_ZCODE;
i = buffer3->1;
#Ifnot; ! TARGET_GLULX
i = buffer3-->0;
#Endif;
while (buffer3->(i + WORDSIZE - 1) == ' ' or '.')
i--;
j = i - WordLength(verb_wordnum); ! amount to move buffer up by
if (j > 0) {
for (m=INPUT_BUFFER_LEN-1 : m>=WORDSIZE+j : m--)
buffer->m = buffer->(m-j);
#Ifdef TARGET_ZCODE;
buffer->1 = buffer->1 + j;
#Ifnot; ! TARGET_GLULX
buffer-->0 = buffer-->0 + j;
#Endif;
}
for (m=WORDSIZE : m<WORDSIZE+i : m++) buffer->m = buffer3->m;
if (j < 0) for (:m<WORDSIZE+i-j : m++) buffer->m = ' ';
} else
for (i=0 : i<INPUT_BUFFER_LEN : i++) buffer->i = buffer3->i;
jump ReParse;
}
! Save the present input in case of an "again" next time
if (verb_word ~= AGAIN1__WD)
for (i=0 : i<INPUT_BUFFER_LEN : i++) buffer3->i = buffer->i;
if (usual_grammar_after == 0) {
j = verb_wordnum;
i = RunRoutines(actor, grammar);
#Ifdef DEBUG;
if (parser_trace >= 2 && actor.grammar ~= 0 or NULL)
print " [Grammar property returned ", i, "]^";
#Endif; ! DEBUG
#Ifdef TARGET_ZCODE;
if ((i ~= 0 or 1) &&
(UnsignedCompare(i, dict_start) < 0 ||
UnsignedCompare(i, dict_end) >= 0 ||
(i - dict_start) % dict_entry_size ~= 0)) {
usual_grammar_after = j;
i=-i;
}
#Ifnot; ! TARGET_GLULX
if (i < 0) { usual_grammar_after = verb_wordnum; i=-i; }
#Endif;
if (i == 1) {
results-->0 = action;
results-->1 = 2; ! [VERGIT] Aqu<ED> va el n<FA>mero de par<E1>metros
results-->2 = noun;
results-->3 = second;
rtrue;
}
if (i ~= 0) { verb_word = i; wn--; verb_wordnum--; }