Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next



  • Volume 2 - The Inform 6 Parser Template File

    Book - Basic Definitions and Utilities


    Chapter - Grammar Line Variables

    [This is the I6 library parser in mostly untouched form: reformatted for template
    file use, and with paragraph divisions, but otherwise hardly changed at all.
    It is a complex algorithm but one which is known to produce good results for
    the most part, and it is well understood from (at time of writing) fifteen
    years of use. A few I7 additions have been made, but none disrupting the
    basic method. For instance, I7's system for resolving ambiguities is
    implemented by providing a |ChooseObjects| routine, just as a user of the
    I6 library would do.

    The I6 parser uses a huge number of global variables, which is not to modern
    programming tastes: in the early days of Inform, the parser was essentially
    written in assembly-language only lightly structured by C-like syntaxes,
    and the Z-machine's 240 globals were more or less registers. The I6 library
    made no distinction between which were ``private'' to the parser and which
    allowed to be accessed by the user's code at large. The I7 template does
    impose that boundary, though not very strongly: the variables defined
    in ``Output.i6t'' are for general access, while the ones below should only
    be read or written by the parser.
    ]

    Include (-
    Global best_etype; ! Preferred error number so far
    Global nextbest_etype; ! Preferred one, if ASKSCOPE_PE disallowed
    Global parser_inflection; ! A property (usually "name") to find object names in

    Array pattern --> 32; ! For the current pattern match
    Global pcount; ! and a marker within it
    Array pattern2 --> 32; ! And another, which stores the best match
    Global pcount2; ! so far

    Array line_ttype-->32; ! For storing an analysed grammar line
    Array line_tdata-->32;
    Array line_token-->32;

    Global nsns; ! Number of special_numbers entered so far

    Global params_wanted; ! Number of parameters needed (which may change in parsing)

    Global inferfrom; ! The point from which the rest of the command must be inferred
    Global inferword; ! And the preposition inferred
    Global dont_infer; ! Another dull flag

    Global cobj_flag = 0;

    Global oops_from; ! The "first mistake" word number
    Global saved_oops; ! Used in working this out
    Array oops_workspace -> 64; ! Used temporarily by "oops" routine

    Global held_back_mode; ! Flag: is there some input from last time
    Global hb_wn; ! left over? (And a save value for wn.)
    ! (Used for full stops and "then".)

    Global usual_grammar_after; ! Point from which usual grammar is parsed (it may vary from
    ! the above if user's routines match multi-word verbs)
    -) after "Utilities.i6t".

    The best parser error so far is a command parser error that varies.
    The second-best parser error so far is a command parser error that varies.

    Have more to parse is a truth state that varies.
    The have more to parse variable translates into I6 as "held_back_mode".
    The word position we held back at is a number that varies.
    The word position we held back at variable translates into I6 as "hb_wn".

    The best parser error so far variable translates into I6 as "best_etype".
    The second-best parser error so far variable translates into I6 as "nextbest_etype"

    The count of non-objects is a number that varies.
    The count of non-objects variable translates into I6 as "nsns".

    The inferred preposition is an understood word that varies.
    The inferred preposition variable translates into I6 as "inferword".

    The predicate's position is a number that varies.
    The predicate's position variable translates into I6 as "usual_grammar_after".

    The current names list is an understood word valued property that varies.
    To decide which 0-based index based rulebook producing pattern unions is the player's understood command:
    (-pattern-).
    [To decide which 0-based index based rulebook producing objects is the player's understood command as objects:
    (-pattern-).
    To decide which 0-based index based rulebook producing understood words is the player's understood command as understood words:
    (-pattern-).]

    To decide which 0-based index based rulebook producing pattern unions is the player's saved understood command:
    (-pattern2-).
    [To decide which 0-based index based rulebook producing objects is the player's saved command as objects:
    (-pattern2-).
    To decide which 0-based index based rulebook producing understood words is the player's saved command as understood words:
    (-pattern2-).]

    The understood command's current position is a number[pattern index] that varies.
    The second understood command's current position is a number[pattern index] that varies.
    The number of parameters for this line is a number that varies.
    Make inferences is a truth state that varies. [ Parser.i6t has the value of this boolean swapped. Negatives don't read well in my opinion so I try to do what I can. ]
    Where inferring the pattern from is a number[pattern index] that varies.
    Remember where the typo's at is a number[pattern index] that varies

    The ranking strategy is a number that varies.

    To decide which 1-based index based rulebook producing zscii letters is the previous turn's input: (-oops_workspace-).
    Where the previous typo's at is a [word position] number that varies.


    To decide which 0-based index based rulebook producing grammar tokens is the grammar line tokens: (-line_token-).
    To decide which 0-based index based rulebook producing token types is the grammar line types: (-line_ttype-).
    To decide which 0-based index based rulebook producing grammar tokens is the grammar line data: (-line_tdata-).
    [max sizes are 32]
    To decide which token type is this token's type: (- line_ttype-->pcount -).
    To decide which grammar token is this grammar token: (- line_tdata-->pcount -).
    To decide which grammar token is this grammar element: (- line_token-->pcount -).

    The current names list variable translates into I6 as "parser_inflection".
    The understood command's current position variable translates into I6 as "pcount".
    The second understood command's current position variable translates into I6 as "pcount2".
    The number of parameters for this line variable translates into I6 as "params_wanted".
    Where inferring the pattern from variable translates into I6 as "inferfrom".
    Make inferences variable translates into I6 as "dont_infer". [ this boolean's value is negated in Parser.i6t ]
    The ranking strategy variable translates into I6 as "cobj_flag".
    Where the previous typo's at variable translates into I6 as "oops_from".
    Remember where the typo's at variable translates into I6 as "saved_oops".