Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 5 - Compare two dictionary/string words, compare typed word and string/dictionary word (considering all characters)

    Include (-

    Array wc1 -> DICT_WORD_SIZE + WORDSIZE + 2;
    Array wc2 -> DICT_WORD_SIZE + WORDSIZE + 2;


    [ WordCompare w1 w2 max_compare_length u;

        if (max_compare_length == 0) max_compare_length = DICT_WORD_SIZE;

    ! for text and dicts

        VM_PrintToBuffer(wc1, max_compare_length, w1); ! print word
        VM_PrintToBuffer(wc2, max_compare_length, w2); ! print word
        

        !print (string) w1, "/", (address) w2, "/", wc1-->0, "/", wc2-->0, "/^";
        
        if (wc1-->0 ~= wc2-->0) rfalse;
        
        for (u = WORDSIZE : u < (wc1-->0) + WORDSIZE: u++)
        {
        ! print (char) wc1->u, ":", (char) wc2->u, "... ";
            if (glk_char_to_lower(wc1->u) ~= glk_char_to_lower(wc2->u)) rfalse;
        }


        rtrue;
    ];

    -).

    Include (-

    [ CompareTextAndPlayersInput text_word wordnum print_buffer
        i players_word_length players_word
        ;

        players_word_length = WordLength(wordnum);
        players_word = WordAddressInBuffer(wordnum, print_buffer);
        VM_PrintToBuffer(test_bed, players_word_length + 1, text_word);

        !glk_set_window((+main-window+).ref_number);
        !print "Typed length = ", players_word_length, "^";
        
        if (test_bed-->0 ~= players_word_length)
        {
            !print "NOT LONG ENOUGH.^";
            rfalse;
        }
            
        for (i = 0 : i < players_word_length : i++)
        {
            !print (char) players_word->i, " / ", (char) test_bed->(i + WORDSIZE);
            if (players_word->i ~= test_bed->(i + WORDSIZE))
                rfalse;
        }
        
        rtrue;
        
    ];

    -).