Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next

  • Chapter - Print Command

    [|PrintCommand| reconstructs the command as it presently reads, from the
    pattern which has been built up.

    If |from| is 0, it starts with the verb: then it goes through the pattern.

    The other parameter is |emptyf| -- a flag: if 0, it goes up to |pcount|:
    if 1, it goes up to |pcount|-1.

    Note that verbs and prepositions are printed out of the dictionary:
    and that since the dictionary may only preserve the first six characters
    of a word (in a V3 game), we have to hand-code the longer words needed.
    At present, I7 doesn't do this, but it probably should.

    (Recall that pattern entries are 0 for ``multiple object'', 1 for ``special
    word'', 2 to |REPARSE_CODE-1| are object numbers and |REPARSE_CODE+n| means
    the preposition |n|.)]

    To clarify the parser's choice of (inferred - a number) -th element (this is PrintInferredCommand):
        if inferred is not 0 and inferred is the understood command's current position minus 1: [ ensure valid array index ]
            let the item be the inferred element of the player's understood command;
            if the item is currently an object:
                begin the clarifying the parser’s choice activity with the item as an object;
                if handling clarifying the parser’s choice activity with the item as an object, say "([recap of command from inferred])[line break]";
                end the clarifying the parser’s choice activity with the item as an object;
        say "([recap of command from inferred])[line break]".

    [ PrintInferredCommand from singleton_noun;
        singleton_noun = FALSE;
        if ((from ~= 0) && (from == pcount-1) &&
            (pattern-->from > 1) && (pattern-->from < REPARSE_CODE))
                singleton_noun = TRUE;

        if (singleton_noun) {
            BeginActivity(CLARIFYING_PARSERS_CHOICE_ACT, pattern-->from);
            if (ForActivity(CLARIFYING_PARSERS_CHOICE_ACT, pattern-->from) == 0) {
                print "("; PrintCommand(from); print ")^";
            EndActivity(CLARIFYING_PARSERS_CHOICE_ACT, pattern-->from);
        } else {
            print "("; PrintCommand(from); print ")^";

    To say recap of command from (position to recap from - number) (this is PrintCommand):
        let need a space be false;
        if the position to recap from is 0:
            if the verb is an abbreviation then say its expanded form otherwise:
                if the verb is invalid then say so otherwise:
                    say the verb [as-is];
            increment the position to recap from;
            we will need a space;
        repeat through the player's understood command of size the understood command's current position starting at the position to recap from:
            let i be the player's understood command element;
            if i is the null pattern, next;
            if we need a space, say " ";
            if i is a bunch of objects:
                say "those things";
            otherwise if i is that special word:
                say "that";
            otherwise if i is currently an understood word:
                say "[i as an understood word]";
                say the i as an object;
            we may need a space again.

    [ PrintCommand from; ];

    [! otherwise known as I7's "recap of command" -- when used without a parameter;]
    [ PrintCommand from i k spacing_flag;
    if (from == 0) {
    i = verb_word;
    if (LanguageVerb(i) == 0)
    if (PrintVerb(i) == 0) print (address) i;
    from++; spacing_flag = true;
    for (k=from : k<pcount : k++) {
    i = pattern-->k;
    if (i == PATTERN_NULL) continue;
    if (spacing_flag) print (char) ' ';
    if (i == 0) { print (string) THOSET__TX; jump TokenPrinted; }
    if (i == 1) { print (string) THAT__TX; jump TokenPrinted; }
    if (i >= REPARSE_CODE)
    print (address) VM_NumberToDictionaryAddress(i-REPARSE_CODE);
    if (i ofclass K3_direction)
    print (LanguageDirection) i; ! the direction name as adverb
    print (the) i;
    spacing_flag = true;