Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter - Parsing Descriptors

    [The |Descriptors()| routine parses the descriptors at the head of a noun
    phrase, leaving the current word marker |wn| at the first word of the
    noun phrase's body. It is allowed to set up for a plural only if |allow_p|
    is set; it returns a parser error number, or 0 if no error occurred.]

    [ One place sends a truth state to this function, but it erases its value almost immediately. ]
    To decide which command parser error is the result of parsing determiners like ALL\OTHER\FIVE\MY\THESE\HIS\THE\AN\SOME\etc (this is Descriptors):
        reset descriptor words;
        if the parser's current word position is greater than the number of words in the command, decide on no errors here;
        let get another word be true;
        while we still get another word: [ This wants to be a test-at-the-bottom loop containing an else-if chain. ]
            let the word be the next word if any;
            we shouldn't get another word;
            if the word is listed as one of the descriptors in the language's descriptor list:
                let its type be the category element;
                unless its type is like 'THE':
                    now the indefinite article mode is true;
                we now assume leading words to be descriptors;
                exclude all except the gender-animation element from the grammatical case;
                if its type is like 'MY\THESE\HIS' etc:
                    if the possessive descriptor element is 'MY\THIS\THESE':
                        include a possessive descriptor in the type of descriptor word used;
                    otherwise if the possessive descriptor element is 'THAT\THOSE':
                        include a THAT descriptor in the type of descriptor word used;
                    otherwise[ if the possessive descriptor element is 'HIS\HER\THEIR\ITS']:
                        now what the pronoun stands for is what the possessive descriptor element stands for;
                otherwise if its type is 'LIT\LIGHTED':
                    include a lit descriptor in the type of descriptor word used;
                otherwise if its type is 'UNLIT':
                    include an unlit descriptor in the type of descriptor word used;
                we should get another word;
            if the word is 'OTHER':
                include an OTHER descriptor in the type of descriptor word used;
                now the indefinite article mode is true;
                we should get another word;
    [ if the word is 'OF' and the number of consecutive descriptor words is at least 2:
                do nothing; [ we may not wish to skip OF if it leads the next phrase, only if it follows ALL, TWO, etc.]
                we should get another word; ]
            if the word is 'ALL':
                include a Plural descriptor in the type of descriptor word used;
                now the indefinite article mode is true;
                now the number of items wanted is all items are wanted;
                if the TAKE ALL exception is 1, now the TAKE ALL exception is 2;
                we should get another word;
            if we allow numeric words as descriptors:[the 'three' in 'take three rocks' but not 'take the Memphis Three' ]
                let finished be whether or not the next word if any is no more words left to parse;
                decrement the parser's current word position;
                if we haven't finished:
                    let the typed-in numeric word be the number typed in by the player at the parser's current word position - 1; [ which returns negative numbers if the player didn't use one]
                    if the typed-in numeric word is at least 1:
                        now the indefinite article mode is true;
                        we should get another word;
                        if the typed-in numeric word is at least 2:
                            include a plural descriptor in the type of descriptor word used;
                            now probably plural is true;
                            now the number of items wanted is the typed-in numeric word;
                            now where we found a number used like an adjective is the parser's current word position - 1;
            if we should get another word:
                unless the next word if any is 'OF':
                    decrement the parser's current word position;
        decrement the parser's current word position;
        decide on no errors here.


    [ Descriptors o x flag cto type n;
    ResetDescriptors();
    if (wn > num_words) return 0;

    for (flag=true : flag :) {
    o = NextWordStopped(); flag = false;

    for (x=1 : x<=LanguageDescriptors-->0 : x=x+4)
    if (o == LanguageDescriptors-->x) {
    flag = true;
    type = LanguageDescriptors-->(x+2);
    if (type ~= DEFART_PK) indef_mode = true;
    indef_possambig = true;
    indef_cases = indef_cases & (LanguageDescriptors-->(x+1));

    if (type == POSSESS_PK) {
    cto = LanguageDescriptors-->(x+3);
    switch (cto) {
    0: indef_type = indef_type | MY_BIT;
    1: indef_type = indef_type | THAT_BIT;
    default:
    indef_owner = PronounValue(cto);
    if (indef_owner == NULL) indef_owner = InformParser; ! this should never happen: POSSESS_PK + NULL
    }
    }

    if (type == light) indef_type = indef_type | LIT_BIT;
    if (type == -light) indef_type = indef_type | UNLIT_BIT;
    }

    if (o == OTHER1__WD or OTHER2__WD or OTHER3__WD) {
    indef_mode = 1; flag = 1;
    indef_type = indef_type | OTHER_BIT;
    }
    if (o == ALL1__WD or ALL2__WD or ALL3__WD or ALL4__WD or ALL5__WD) {
    indef_mode = 1; flag = 1; indef_wanted = INDEF_ALL_WANTED;
    if (take_all_rule == 1) take_all_rule = 2;
    indef_type = indef_type | PLURAL_BIT;
    }
    if (allow_plurals) {
    if (NextWordStopped() ~= -1) { wn--; n = TryNumber(wn-1); } else { n=0; wn--; }
    if (n == 1) { indef_mode = 1; flag = 1; }
    if (n > 1) {
    indef_guess_p = 1;
    indef_mode = 1; flag = 1; indef_wanted = n;
    indef_nspec_at = wn-1;
    indef_type = indef_type | PLURAL_BIT;
    }
    }
    if (flag == 1 && NextWordStopped() ~= OF1__WD or OF2__WD or OF3__WD or OF4__WD)
    wn--; ! Skip 'of' after these
    }
    wn--;
    return 0;
    ]

    To skip over any descriptor words (this is SafeSkipDescriptors):
        save the indefinite article mode;
        save the type of descriptor word used;
        save the number of items wanted;
        save probably plural;
        save assume leading words to be descriptors;
        save what the pronoun stands for;
        save the grammatical case;
        save where we found a number used like an adjective;
        Let the ignored error be the result of parsing determiners like ALL\OTHER\FIVE\MY\THESE\HIS\THE\AN\SOME\etc;
        restore where we found a number used like an adjective;
        restore the grammatical case;
        restore what the pronoun stands for;
        restore assume leading words to be descriptors;
        restore probably plural;
        restore the number of items wanted;
        restore the type of descriptor word used;
        restore the indefinite article mode.

    [ SafeSkipDescriptors;
        @push indef_mode; @push indef_type; @push indef_wanted;
        @push indef_guess_p; @push indef_possambig; @push indef_owner;
        @push indef_cases; @push indef_nspec_at;
        
        Descriptors();
        
        @pull indef_nspec_at; @pull indef_cases;
        @pull indef_owner; @pull indef_possambig; @pull indef_guess_p;
        @pull indef_wanted; @pull indef_type; @pull indef_mode;
    ]