Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter 4 - Parser Data

    Section 6 - Byte arrays of input

    Include (-

    [ WordUnderCursor cur_pos
        i;
    ! glk_set_window((+main-window+).ref_number);
    ! print "Word Under Cursor: ", cur_pos, ".^";
        for (i = 1: i < WordCount() : i++)
        {
    ! print "(word ", i + 1, " starts at " , CharacterNumber(i+1), "...^";
            if (CharacterNumber(i + 1) - 1 > cur_pos)
            {
    ! print "Word Under Cursor = ", i, "^";
                 return i;
            }
        }
    ! print "Word Under Cursor (F) = ", WordCount(), "^";
        return WordCount();
    ];



    [ WordAddressInBuffer wordnum this_buffer;
        return this_buffer + CharacterAddress(wordnum);
    ];


    [ CharacterAddress wordnum;
        ! in the parsed buffer
        #ifdef TARGET_ZCODE;
            return parse->(wordnum * 4 + 1);
        #ifnot;
            return parse-->(wordnum*3);
        #endif;
    ];

    [ CharacterNumber wordnum;
        ! in actual text string of input
        return CharacterAddress(wordnum) - WORDSIZE + 1;
    ];

    [ DictionaryValue wordnum;
        #ifdef TARGET_ZCODE;
            return parse-->(wordnum * 2 - 1);
        #ifnot;
            return parse-->(wordnum * 3 - 2);
        #endif;

    ];

    -).