Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter - Noticing Plurals

    [ This is called by the auto-generated Inform 7 source when it compiles Understand lines. Beside returning whether it found a plural word in a run of words, it also set's "what the parser's doing" to that fact. ]

    To decide whether any plural words exist starting at (position - a number) for (length - a number) (this is DetectPluralWord):
        let the saved position be the parser's current word position;
        now the parser's current word position is the position;
        repeat with each word running from one to the length:
            let the current word be the next word if any;
            if the current word is either 'THEN' or the comma or a word unknown by the game or no more words left to parse:
                break;
            if the usages of the current word include being plural:
                now what the parser's doing is identifying plurals;
                now the parser's current word position is the saved position;
                yes;
        now the parser's current word position is the saved position;
        no.

    [ DetectPluralWord at n i w swn outcome;
        swn = wn; wn = at;
        for (i=0:i<n:i++) {
            w = NextWordStopped();
            if (w == 0 or THEN1__WD or COMMA_WORD or -1) break;
            if ((w->#dict_par1) & $$00000100) {
                parser_action = ##PluralFound;
                outcome = true;
            }
        }
        wn = swn;
        return outcome;
    ]