Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 6 - Word in Scope used to create quick lookup lists

    Include (-

    !Constant MAX_WORD_IN_SCOPE = 256;
    !Constant MAX_VERB_NAMES = 300;
    !Constant MAX_COMPASS_NAMES = 35;

    Array word_in_scope_list --> MAX_WORD_IN_SCOPE + 2;
    Array word_for_verb_list --> MAX_VERB_NAMES + 2;
    Array word_in_compass_list --> MAX_COMPASS_NAMES + 2;

    [ WorkThroughScope
        parent_of_scope
        scope_list_name
        scope_list_size
        word_type_include
        property_include
        
        error_text_type
        error_text_use_option

        j
        ;
        scope_list_name --> 0 = 0;
        
        for (j = dictstart : j < dictstart + dictlen * entrylen : j = j + entrylen)
        {
            if (WordInScope(j, parent_of_scope) || (word_type_include ~= EX_NONE && WordType(j) == word_type_include) ||
                ( property_include > 0 && WordInScope(j, location, property_include) ) )
            {
                (scope_list_name-->0)++;
                if (scope_list_name-->0 < scope_list_size)
                    scope_list_name-->(scope_list_name-->0) = j;
            }
        }

        if (scope_list_name-->0 >= scope_list_size )
        {

            glk_set_window((+main-window+).ref_number);
            print "*** Interactive Parsing Error: Out of scoped words for ", (string) error_text_type, ". Please increase the limit (which is currently ", scope_list_size, ") using the command:^^Use ", (string) error_text_use_option, " of at least ", scope_list_name-->0 + 2, ".^^";

            scope_list_name-->0 = 0;
        }

    ! #ifdef DEBUG;
    ! glk_set_window((+main-window+).ref_number);
    ! print "Scope list size:", scope_list_name-->0 ," for ", (the) parent_of_scope, "^";
    ! #endif;

    ];


    [ WordInScope w r p;
    ! approximate scope rules to help choose the preferable object
    ! doesn't prevent player from checking if a word is recognised
    ! if p is specified, we require this too

    while (r) {
    if (WordInProperty(w, r, name))
            {
                if (p == 0 || (p > 0 && r has p)) rtrue;
            }

    #Ifdef pname;
    if (r provides pname && WordInProperty(w, r, pname))
            {
                if (p == 0 || (p > 0 && r has p)) rtrue;
            }
    #Endif;

    #Ifdef scenic;
    if (r provides scenic && WordInProperty(w, r, scenic))
            {
                if (p == 0 || (p > 0 && r has p)) rtrue;
            }
    #Endif;

    ! find the next object
    if (child(r) && (r hasnt container || r has transparent or open or supporter
    or visited))
    r = child(r); ! ?? if (r==Darkness) r=player;
    else {
    while (r && sibling(r) == 0)
    r = parent(r);
    if (r)
    (r = sibling(r));
    }
    }
    ! could also check articles etc at this point when nouns are expected - only using for Compass, though, so not needed
    ! for (r=1: r<=LanguageDescriptors-->0: r=r+4) if (w == LanguageDescriptors-->r or LanguageDescriptors-->(r+3)) rtrue;

    rfalse;
    ];

    [ CheckCompassWords check_word i;
        for (i = 1: i <= word_in_compass_list-->0 : i++) if (check_word == word_in_compass_list-->i)
        {
    ! glk_set_window((+main-window+).ref_number);
    ! print "Compass word found: ", (address) check_word, "^";
                rtrue;
        }

    ! glk_set_window((+main-window+).ref_number);
    ! print "Compass word NOT FOUND: ", (address) check_word, "^";

        rfalse;

    ];

    -)