



TryGivenObject (lines 3975-4077)
Back to List
Browsing parserm.h
3975 ! TryGivenObject tries to match as many words as possible in what has been
3976 ! typed to the given object, obj. If it manages any words matched at all,
3977 ! it calls MakeMatch to say so, then returns the number of words (or 1
3978 ! if it was a match because of inadequate input).
3979 ! ----------------------------------------------------------------------------
3980
3981 [ TryGivenObject obj threshold k w j;
3982 #Ifdef DEBUG;
3983 if (parser_trace >= 5) print " Trying ", (the) obj, " (", obj, ") at word ", wn, "^";
3984 #Endif; ! DEBUG
3985
3986 dict_flags_of_noun = 0;
3987
3988 ! If input has run out then always match, with only quality 0 (this saves
3989 ! time).
3990
3991 if (wn > num_words) {
3992 if (indef_mode ~= 0)
3993 dict_flags_of_noun = $$01110000; ! Reject "plural" bit
3994 MakeMatch(obj,0);
3995 #Ifdef DEBUG;
3996 if (parser_trace >= 5) print " Matched (0)^";
3997 #Endif; ! DEBUG
3998 return 1;
3999 }
4000
4001 ! Ask the object to parse itself if necessary, sitting up and taking notice
4002 ! if it says the plural was used:
4003
4004 if (obj.parse_name~=0) {
4005 parser_action = NULL; j=wn;
4006 k = RunRoutines(obj,parse_name);
4007 if (k > 0) {
4008 wn=j+k;
4009
4010 .MMbyPN;
4011
4012 if (parser_action == ##PluralFound)
4013 dict_flags_of_noun = dict_flags_of_noun | 4;
4014
4015 if (dict_flags_of_noun & 4) {
4016 if (~~allow_plurals) k = 0;
4017 else {
4018 if (indef_mode == 0) {
4019 indef_mode = 1; indef_type = 0; indef_wanted = 0;
4020 }
4021 indef_type = indef_type | PLURAL_BIT;
4022 if (indef_wanted == 0) indef_wanted = 100;
4023 }
4024 }
4025
4026 #Ifdef DEBUG;
4027 if (parser_trace >= 5) print " Matched (", k, ")^";
4028 #Endif; ! DEBUG
4029 MakeMatch(obj,k);
4030 return k;
4031 }
4032 if (k == 0) jump NoWordsMatch;
4033 }
4034
4035 ! The default algorithm is simply to count up how many words pass the
4036 ! Refers test:
4037
4038 parser_action = NULL;
4039
4040 w = NounWord();
4041
4042 if (w == 1 && player == obj) { k=1; jump MMbyPN; }
4043
4044 if (w >= 2 && w < 128 && (LanguagePronouns-->w == obj)) { k = 1; jump MMbyPN; }
4045
4046 j=--wn;
4047 threshold = ParseNoun(obj);
4048 #Ifdef DEBUG;
4049 if (threshold >= 0 && parser_trace >= 5) print " ParseNoun returned ", threshold, "^";
4050 #Endif; ! DEBUG
4051 if (threshold < 0) wn++;
4052 if (threshold > 0) { k = threshold; jump MMbyPN; }
4053
4054 if (threshold == 0 || Refers(obj,wn-1) == 0) {
4055 .NoWordsMatch;
4056 if (indef_mode ~= 0) {
4057 k = 0; parser_action = NULL;
4058 jump MMbyPN;
4059 }
4060 rfalse;
4061 }
4062
4063 if (threshold < 0) {
4064 threshold = 1;
4065 dict_flags_of_noun = (w->#dict_par1) & $$01110100;
4066 w = NextWord();
4067 while (Refers(obj, wn-1)) {
4068 threshold++;
4069 if (w)
4070 dict_flags_of_noun = dict_flags_of_noun | ((w->#dict_par1) & $$01110100);
4071 w = NextWord();
4072 }
4073 }
4074
4075 k = threshold;
4076 jump MMbyPN;
4077 ];
Last updated 27 February 2004. The librarian in charge of this page is Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight. Please email any comments, suggestions or corrections to cedenqs@inform-fiction.org.