Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 3 - Some functions for shifting buffers around

    Include (-

    [ AdvanceParseFromSecondBuffer result;
        ! Store the buffer; copy buffer2 into place of buffer for use by the parser
        VM_CopyBuffer(buffer3, buffer);
        VM_CopyBuffer(buffer, buffer2);
        
        ! use buffer
        VM_Tokenise(buffer, parse);
        result = PerformAdvanceParse(false);
        
    ! glk_set_window((+main-window+).ref_number);
    ! print "Achieved a result of ", result, ".^";
        
        ! repair the buffer before we destroy anything the player's typed
        VM_CopyBuffer(buffer, buffer3);
        
        return result;
    ];

    [ BuildSecondBuffer input_buffer old_word_start old_word_length new_word
        i j
        ;
        
    ! glk_set_window((+main-window+).ref_number);
    ! print "Building advance parser buffer over start ", old_word_start, ", length ", old_word_length, ", and inserting new word ", (address) new_word , " to give : ";
        
        ! TODO: cope with placing a suggestion anywhere except the last word

        ! word transformed to byte array
        VM_PrintToBuffer(test_bed, DICT_WORD_SIZE, new_word);
        
        ! build new buffer2
        for ( i = 0 : i < input_buffer-->0 - old_word_length + test_bed-->0 : i++)
        {
            if ( i < old_word_start - 1)
            {
                ! copy the first part of the buffer straight
                buffer2->(i + WORDSIZE) = input_buffer->(i + WORDSIZE);
            }
        ! eg. examine broze cross (sub in ABOUT)
        ! ows = 9, tb0 = 5 (14)
        ! when i = 13 start writing in (from the space)
        ! start writing in from position 13 + WORDSIZE = 13 - 5 + 5 + WORDSIZE)
            else if (i >= old_word_start + test_bed-->0 - 1) {
                ! copy the second part of the buffer straight
                buffer2->(i + WORDSIZE) = input_buffer->(i - test_bed-->0 + old_word_length + WORDSIZE);
            }
            else
            {
                buffer2->(i + WORDSIZE) = test_bed->(j + WORDSIZE);
                j++;
            }
    ! print (char) buffer2->(i+WORDSIZE);
        }

        buffer2-->0 = input_buffer-->0 + test_bed-->0 - old_word_length;

        
    ! print " (new length = ", buffer2-->0, ".^";


    ];

    -).