Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next



  • Book - Text to Name Matching

    Chapter - Parsing Object Names

    [We now reach the final major block of code in the parser: the part which tries
    to match a given object's name(s) against the text at word position |match_from|
    in the player's command, and calls |MakeMatch| if it succeeds. There are
    basically four possibilities: ME, a pronoun such as IT, a name which doesn't
    begin misleadingly with a number, and a name which does. In the latter two
    cases, we pass the job down to |TryGivenObject|.]

    To decide if (item - an object) is the antecedent for (i - an understood [pronoun] word):
    (- (({i} >= 2) && ({i} < 128) && (LanguagePronouns-->{i} == {item})) -).

    To match text against (item - an object) (this is MatchTextAgainstObject):
        if the next word to parse's position <= the number of words in the command:
            now the parser's current word position is the next word to parse's position;
            let the appropriate word be the possibility that it's a noun;
            [ Possibility 1: "me" ]
            if the item is the player and the appropriate word is ME The Player:
                add the item to the match list assuming 1 qualifies it;
            [ Possibility 2: a pronoun ]
            if the item is the antecedent for the appropriate word:
                 add the item to the match list assuming 1 qualifies it;
        now the parser's current word position is [set back to] the next word to parse's position;
        if how many words the item can match is at least 1:
            if where we found a number used like an adjective > 0 and where we found a number used like an adjective is not [at] the next word to parse's position:
                [ This case arises if the player has typed a number in
                ! which is hypothetically an indefinite descriptor:
                ! e.g. "take two clubs". We have just checked the object
                ! against the word "clubs", in the hope of eventually finding
                ! two such objects. But we also backtrack and check it
                ! against the words "two clubs", in case it turns out to
                ! be the 2 of Clubs from a pack of cards, say. If it does
                ! match against "two clubs", we tear up our original
                ! assumption about the meaning of "two" and lapse back into
                ! definite mode.]
                now the parser's current word position is where we found a number used like an adjective;
                if how many words the item can match is at least 1:
                    now the next word to parse's position is where we found a number used like an adjective;
                    reset descriptor words;
                now the parser's current word position is the next word to parse's position.


    [ MatchTextAgainstObject item i;
        if (match_from <= num_words) { ! If there's any text to match, that is
            wn = match_from;
            i = NounWord();
            if ((i == 1) && (player == item)) MakeMatch(item, 1); ! "me"
            if ((i >= 2) && (i < 128) && (LanguagePronouns-->i == item)) MakeMatch(item, 1);
        }

        ! Construing the current word as the start of a noun, can it refer to the
        ! object?

        wn = match_from;
        if (TryGivenObject(item) > 0)
            if (indef_nspec_at > 0 && match_from ~= indef_nspec_at) {
                ! This case arises if the player has typed a number in
                ! which is hypothetically an indefinite descriptor:
                ! e.g. "take two clubs". We have just checked the object
                ! against the word "clubs", in the hope of eventually finding
                ! two such objects. But we also backtrack and check it
                ! against the words "two clubs", in case it turns out to
                ! be the 2 of Clubs from a pack of cards, say. If it does
                ! match against "two clubs", we tear up our original
                ! assumption about the meaning of "two" and lapse back into
                ! definite mode.

                wn = indef_nspec_at;
                if (TryGivenObject(item) > 0) {
                    match_from = indef_nspec_at;
                    ResetDescriptors();
                }
                wn = match_from;
            }
    ]