Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 3 - The Advance Parsing Routine, for use by anyone - returns length of match made (and sets context vars)

    Include (-

    Constant RETURN_TO_INPUT_LINE = 3;
    Constant PERFORMING = 2;
    Constant ERROR_GIVEN = 1;
    Constant INACTIVE = 0;

    Constant EX_NONE = -1;
    Constant EX_NOUN = 0;
    Constant EX_VERB = 1;
    Constant EX_PREPOSITION = 2;
    Constant EX_ENDOFLINE = 3;

    Global pre_command = 0;

    Global word_understood_to = 0;
    Global command_in_full = false;

    Global next_token_type = 0;

    ! for storing prepositions in, when I get that far...
    Global next_expected_word = 0;


    ! Do a parse. Call with true to store results; false simply to return length of match made
    [ PerformAdvanceParse setting_flags
        i rv j k;

        i = word_understood_to;
        k = command_in_full;
        
        #ifdef DEBUG;
            !glk_set_window ( (+main-window+).ref_number);
        #endif;
        
        pre_command = PERFORMING;
        next_expected_word = 0;
        word_understood_to = -1;
        j = next_token_type;
        
        Parser__parse();

        ! put back global vars

        rv = word_understood_to;

        if (~~setting_flags)
        {
            next_token_type = j;
            word_understood_to = i;
            command_in_full = k;
        }
        pre_command = INACTIVE;

        ! print "Returning ", rv, ".^";
        ! return matched number
        return rv;
        
    ];



    -) before "Language.i6t".