Inform - Support - Source

Back to List

Inventory
Complete

At Start
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing parserm.h

InfixInvSub (lines 1-427)

0001  ! ----------------------------------------------------------------------------
0002  !  PARSERM:  Core of parser.
0003  !
0004  !  Supplied for use with Inform 6                         Serial number 991113
0005  !                                                                 Release 6/10
0006  !  (c) Graham Nelson 1993, 1994, 1995, 1996, 1997, 1998, 1999
0007  !      but freely usable (see manuals)
0008  ! ----------------------------------------------------------------------------
0009  !  Inclusion of "linklpa"
0010  !                   (which defines properties and attributes)
0011  !  Global variables, constants and arrays
0012  !                1: outside of the parser
0013  !                2: used within the parser
0014  !  Inclusion of natural language definition file
0015  !                   (which creates a compass and direction-objects)
0016  !  Darkness and player objects
0017  !  Definition of grammar token numbering system used by Inform
0018  !
0019  !  The InformParser object
0020  !          keyboard reading
0021  !          level 0: outer shell, conversation, errors
0022  !                1: grammar lines
0023  !                2: tokens
0024  !                3: object lists
0025  !                4: scope and ambiguity resolving
0026  !                5: object comparisons
0027  !                6: word comparisons
0028  !                7: reading words and moving tables about
0029  !          pronoun management
0030  !
0031  !  The InformLibrary object
0032  !          main game loop
0033  !          action processing
0034  !          end of turn sequence
0035  !          scope looping, before/after sequence, sending messages out
0036  !          timers, daemons, time of day, score notification
0037  !          light and darkness
0038  !          changing player personality
0039  !          tracing code (only present if DEBUG is set)
0040  !
0041  !  Status line printing, menu display
0042  !  Printing object names with articles
0043  !  Miscellaneous utility routines
0044  !  Game banner, "version" verb, run-time errors
0045  ! ----------------------------------------------------------------------------
0046   
0047  System_file;
0048  Constant NULL = $ffff;
0049   
0050  IFDEF MODULE_MODE;
0051  Constant DEBUG;
0052  Constant Grammar__Version 2;
0053  Include "linklpa";
0054  ENDIF;
0055   
0056  ! ============================================================================
0057  !   Global variables and their associated Constant and Array declarations
0058  ! ----------------------------------------------------------------------------
0059  Global location = InformLibrary;     ! Must be first global defined
0060  Global sline1;                       ! Must be second
0061  Global sline2;                       ! Must be third
0062                                       ! (for status line display)
0063  ! ------------------------------------------------------------------------------
0064  !   Z-Machine and interpreter issues
0065  ! ------------------------------------------------------------------------------
0066  Global top_object;                   ! Largest valid number of any tree object
0067  Global standard_interpreter;         ! The version number of the Z-Machine
0068                                       ! Standard which the interpreter claims
0069                                       ! to support, in form (upper byte).(lower)
0070  Global undo_flag;                    ! Can the interpreter provide "undo"?
0071  Global just_undone;                  ! Can't have two successive UNDOs
0072  Global transcript_mode;              ! true when game scripting is on
0073  IFDEF DEBUG;
0074  Global xcommsdir;                    ! true if command recording is on
0075  ENDIF;
0076  ! ------------------------------------------------------------------------------
0077  !   Time and score
0078  ! (for linkage reasons, the task_* arrays are created not here but in verblib.h)
0079  ! ------------------------------------------------------------------------------
0080  Global turns = 1;                    ! Number of turns of play so far
0081  Global the_time = NULL;              ! Current time (in minutes since midnight)
0082  Global time_rate = 1;                ! How often time is updated
0083  Global time_step;                    ! By how much
0084   
0085  #ifndef MAX_TIMERS;
0086  Constant MAX_TIMERS  32;             ! Max number timers/daemons active at once
0087  #endif;
0088  Array  the_timers  --> MAX_TIMERS;
0089  Global active_timers;                ! Number of timers/daemons actives
0090   
0091  Global score;                        ! The current score
0092  Global last_score;                   ! Score last turn (for testing for changes)
0093  Global notify_mode = true;           ! Score notification
0094  Global places_score;                 ! Contribution to score made by visiting
0095  Global things_score;                 ! Contribution made by acquisition
0096  ! ------------------------------------------------------------------------------
0097  !   The player
0098  ! ------------------------------------------------------------------------------
0099  Global player;                       ! Which object the human is playing through
0100  Global deadflag;                     ! Normally 0, or false; 1 for dead;
0101                                       ! 2 for victorious, and higher numbers
0102                                       ! represent exotic forms of death
0103  ! ------------------------------------------------------------------------------
0104  !   Light and room descriptions
0105  ! ------------------------------------------------------------------------------
0106  Global lightflag = true;             ! Is there currently light to see by?
0107  Global real_location;                ! When in darkness, location = thedark
0108                                       ! and this holds the real location
0109  Global visibility_ceiling;           ! Highest object in tree visible from
0110                                       ! the player's point of view (usually
0111                                       ! the room, sometimes darkness, sometimes
0112                                       ! a closed non-transparent container).
0113   
0114  Global lookmode = 1;                 ! 1=standard, 2=verbose, 3=brief room descs
0115  Global print_player_flag;            ! If set, print something like "(as Fred)"
0116                                       ! in room descriptions, to reveal whom
0117                                       ! the human is playing through
0118  Global lastdesc;                     ! Value of location at time of most recent
0119                                       ! room description printed out
0120  ! ------------------------------------------------------------------------------
0121  !   List writing  (style bits are defined as Constants in "verblibm.h")
0122  ! ------------------------------------------------------------------------------
0123  Global c_style;                      ! Current list-writer style
0124  Global lt_value;                     ! Common value of list_together
0125  Global listing_together;             ! Object number of one member of a group
0126                                       ! being listed together
0127  Global listing_size;                 ! Size of such a group
0128  Global wlf_indent;                   ! Current level of indentation printed by
0129                                       ! WriteListFrom routine
0130   
0131  Global inventory_stage = 1;          ! 1 or 2 according to the context in which
0132                                       ! "invent" routines of objects are called
0133  Global inventory_style;              ! List-writer style currently used while
0134                                       ! printing inventories
0135  ! ------------------------------------------------------------------------------
0136  !   Menus and printing
0137  ! ------------------------------------------------------------------------------
0138  Global pretty_flag = true;           ! Use character graphics, or plain text?
0139  Global menu_nesting;                 ! Level of nesting (0 = root menu)
0140  Global menu_item;                    ! These are used in communicating
0141  Global item_width = 8;               ! with the menu-creating routines
0142  Global item_name = "---";
0143   
0144  Global lm_n;                         ! Parameters used by LibraryMessages
0145  Global lm_o;                         ! mechanism
0146   
0147  IFDEF DEBUG;
0148  Global debug_flag;                   ! Bitmap of flags for tracing actions,
0149                                       ! calls to object routines, etc.
0150  Global x_scope_count;                ! Used in printing a list of everything
0151                                       ! in scope
0152  ENDIF;
0153  ! ------------------------------------------------------------------------------
0154  !   Action processing
0155  ! ------------------------------------------------------------------------------
0156  Global action;                       ! Action currently being asked to perform
0157  Global inp1;                         ! 0 (nothing), 1 (number) or first noun
0158  Global inp2;                         ! 0 (nothing), 1 (number) or second noun
0159  Global noun;                         ! First noun or numerical value
0160  Global second;                       ! Second noun or numerical value
0161   
0162  Global keep_silent;                  ! If true, attempt to perform the action
0163                                       ! silently (e.g. for implicit takes,
0164                                       ! implicit opening of unlocked doors)
0165   
0166  Global reason_code;                  ! Reason for calling a "life" rule
0167                                       ! (an action or fake such as ##Kiss)
0168   
0169  Global receive_action;               ! Either ##PutOn or ##Insert, whichever
0170                                       ! is action being tried when an object's
0171                                       ! "before" rule is checking "Receive"
0172  ! ==============================================================================
0173  !   Parser variables: first, for communication to the parser
0174  ! ------------------------------------------------------------------------------
0175  Global parser_trace = 0;             ! Set this to 1 to make the parser trace
0176                                       ! tokens and lines
0177  Global parser_action;                ! For the use of the parser when calling
0178  Global parser_one;                   ! user-supplied routines
0179  Global parser_two;                   !
0180  Array  inputobjs       --> 16;       ! For parser to write its results in
0181  Global parser_inflection;            ! A property (usually "name") to find
0182                                       ! object names in
0183  ! ------------------------------------------------------------------------------
0184  !   Parser output
0185  ! ------------------------------------------------------------------------------
0186  Global actor;                        ! Person asked to do something
0187  Global actors_location;              ! Like location, but for the actor
0188  Global meta;                         ! Verb is a meta-command (such as "save")
0189   
0190  Array  multiple_object --> 64;       ! List of multiple parameters
0191  Global multiflag;                    ! Multiple-object flag
0192  Global toomany_flag;                 ! Flag for "multiple match too large"
0193                                       ! (e.g. if "take all" took over 100 things)
0194   
0195  Global special_word;                 ! Dictionary address for "special" token
0196  Global special_number;               ! Number typed for "special" token
0197  Global parsed_number;                ! For user-supplied parsing routines
0198  Global consult_from;                 ! Word that a "consult" topic starts on
0199  Global consult_words;                ! ...and number of words in topic
0200  ! ------------------------------------------------------------------------------
0201  !   Implicit taking
0202  ! ------------------------------------------------------------------------------
0203  Global notheld_mode;                 ! To do with implicit taking
0204  Global onotheld_mode;                !     "old copy of notheld_mode", ditto
0205  Global not_holding;                  ! Object to be automatically taken as an
0206                                       ! implicit command
0207  Array  kept_results --> 16;          ! Delayed command (while the take happens)
0208  ! ------------------------------------------------------------------------------
0209  !   Error numbers when parsing a grammar line
0210  ! ------------------------------------------------------------------------------
0211  Global etype;                        ! Error number on current line
0212  Global best_etype;                   ! Preferred error number so far
0213  Global nextbest_etype;               ! Preferred one, if ASKSCOPE_PE disallowed
0214   
0215  Constant STUCK_PE     = 1;
0216  Constant UPTO_PE      = 2;
0217  Constant NUMBER_PE    = 3;
0218  Constant CANTSEE_PE   = 4;
0219  Constant TOOLIT_PE    = 5;
0220  Constant NOTHELD_PE   = 6;
0221  Constant MULTI_PE     = 7;
0222  Constant MMULTI_PE    = 8;
0223  Constant VAGUE_PE     = 9;
0224  Constant EXCEPT_PE    = 10;
0225  Constant ANIMA_PE     = 11;
0226  Constant VERB_PE      = 12;
0227  Constant SCENERY_PE   = 13;
0228  Constant ITGONE_PE    = 14;
0229  Constant JUNKAFTER_PE = 15;
0230  Constant TOOFEW_PE    = 16;
0231  Constant NOTHING_PE   = 17;
0232  Constant ASKSCOPE_PE  = 18;
0233  ! ------------------------------------------------------------------------------
0234  !   Pattern-matching against a single grammar line
0235  ! ------------------------------------------------------------------------------
0236  Array pattern --> 32;                ! For the current pattern match
0237  Global pcount;                       ! and a marker within it
0238  Array pattern2 --> 32;               ! And another, which stores the best match
0239  Global pcount2;                      ! so far
0240  Constant PATTERN_NULL = $ffff;       ! Entry for a token producing no text
0241   
0242  Array  line_ttype-->32;              ! For storing an analysed grammar line
0243  Array  line_tdata-->32;
0244  Array  line_token-->32;
0245   
0246  Global parameters;                   ! Parameters (objects) entered so far
0247  Global nsns;                         ! Number of special_numbers entered so far
0248  Global special_number1;              ! First number, if one was typed
0249  Global special_number2;              ! Second number, if two were typed
0250  ! ------------------------------------------------------------------------------
0251  !   Inferences and looking ahead
0252  ! ------------------------------------------------------------------------------
0253  Global params_wanted;                ! Number of parameters needed
0254                                       ! (which may change in parsing)
0255   
0256  Global inferfrom;                    ! The point from which the rest of the
0257                                       ! command must be inferred
0258  Global inferword;                    ! And the preposition inferred
0259  Global dont_infer;                   ! Another dull flag
0260   
0261  Global action_to_be;                 ! (If the current line were accepted.)
0262  Global action_reversed;              ! (Parameters would be reversed in order.)
0263  Global advance_warning;              ! What a later-named thing will be
0264  ! ------------------------------------------------------------------------------
0265  !   At the level of individual tokens now
0266  ! ------------------------------------------------------------------------------
0267  Global found_ttype;                  ! Used to break up tokens into type
0268  Global found_tdata;                  ! and data (by AnalyseToken)
0269  Global token_filter;                 ! For noun filtering by user routines
0270   
0271  Global length_of_noun;               ! Set by NounDomain to no of words in noun
0272  Constant REPARSE_CODE = 10000;       ! Signals "reparse the text" as a reply
0273                                       ! from NounDomain
0274   
0275  Global lookahead;                    ! The token after the one now being matched
0276   
0277  Global multi_mode;                   ! Multiple mode
0278  Global multi_wanted;                 ! Number of things needed in multitude
0279  Global multi_had;                    ! Number of things actually found
0280  Global multi_context;                ! What token the multi-obj was accepted for
0281   
0282  Global indef_mode;                   ! "Indefinite" mode - ie, "take a brick"
0283                                       ! is in this mode
0284  Global indef_type;                   ! Bit-map holding types of specification
0285  Global indef_wanted;                 ! Number of items wanted (100 for all)
0286  Global indef_guess_p;                ! Plural-guessing flag
0287  Global indef_owner;                  ! Object which must hold these items
0288  Global indef_cases;                  ! Possible gender and numbers of them
0289  Global indef_possambig;              ! Has a possibly dangerous assumption
0290                                       ! been made about meaning of a descriptor?
0291  Global indef_nspec_at;               ! Word at which a number like "two" was
0292                                       ! parsed (for backtracking)
0293  Global allow_plurals;                ! Whether plurals presently allowed or not
0294   
0295  Global take_all_rule;                ! Slightly different rules apply to
0296                                       ! "take all" than other uses of multiple
0297                                       ! objects, to make adjudication produce
0298                                       ! more pragmatically useful results
0299                                       ! (Not a flag: possible values 0, 1, 2)
0300   
0301  Global dict_flags_of_noun;           ! Of the noun currently being parsed
0302                                       ! (a bitmap in #dict_par1 format)
0303  Global pronoun_word;                 ! Records which pronoun ("it", "them", ...)
0304                                       ! caused an error
0305  Global pronoun_obj;                  ! And what obj it was thought to refer to
0306  Global pronoun__word;                ! Saved value
0307  Global pronoun__obj;                 ! Saved value
0308  ! ------------------------------------------------------------------------------
0309  !   Searching through scope and parsing "scope=Routine" grammar tokens
0310  ! ------------------------------------------------------------------------------
0311  Constant PARSING_REASON       = 0;   ! Possible reasons for searching scope
0312  Constant TALKING_REASON       = 1;
0313  Constant EACH_TURN_REASON     = 2;
0314  Constant REACT_BEFORE_REASON  = 3;
0315  Constant REACT_AFTER_REASON   = 4;
0316  Constant LOOPOVERSCOPE_REASON = 5;
0317  Constant TESTSCOPE_REASON     = 6;
0318   
0319  Global scope_reason = PARSING_REASON; ! Current reason for searching scope
0320   
0321  Global scope_token;                  ! For "scope=Routine" grammar tokens
0322  Global scope_error;
0323  Global scope_stage;                  ! 1, 2 then 3
0324   
0325  Global ats_flag = 0;                 ! For AddToScope routines
0326  Global ats_hls;                      !
0327   
0328  Global placed_in_flag;               ! To do with PlaceInScope
0329   
0330  ! ------------------------------------------------------------------------------
0331  !   The match list of candidate objects for a given token
0332  ! ------------------------------------------------------------------------------
0333  Constant MATCH_LIST_SIZE = 128;
0334  Array  match_list    --> 64;         ! An array of matched objects so far
0335  Array  match_classes --> 64;         ! An array of equivalence classes for them
0336  Array  match_scores --> 64;          ! An array of match scores for them
0337  Global number_matched;               ! How many items in it?  (0 means none)
0338  Global number_of_classes;            ! How many equivalence classes?
0339  Global match_length;                 ! How many words long are these matches?
0340  Global match_from;                   ! At what word of the input do they begin?
0341  Global bestguess_score;              ! What did the best-guess object score?
0342  ! ------------------------------------------------------------------------------
0343  !   Low level textual manipulation
0344  ! ------------------------------------------------------------------------------
0345  Array  buffer    -> 121;             ! Buffer for parsing main line of input
0346  Array  parse     -> 65;              ! Parse table mirroring it
0347  Array  buffer2   -> 121;             ! Buffers for supplementary questions
0348  Array  parse2    -> 65;              !
0349  Array  buffer3   -> 121;             ! Buffer retaining input for "again"
0350   
0351  Constant comma_word = 'comma,';      ! An "untypeable word" used to substitute
0352                                       ! for commas in parse buffers
0353   
0354  Global wn;                           ! Word number within "parse" (from 1)
0355  Global num_words;                    ! Number of words typed
0356  Global verb_word;                    ! Verb word (eg, take in "take all" or
0357                                       ! "dwarf, take all") - address in dict
0358  Global verb_wordnum;                 ! its number in typing order (eg, 1 or 3)
0359  Global usual_grammar_after;          ! Point from which usual grammar is parsed
0360                                       ! (it may vary from the above if user's
0361                                       ! routines match multi-word verbs)
0362   
0363  Global oops_from;                    ! The "first mistake" word number
0364  Global saved_oops;                   ! Used in working this out
0365  Array  oops_workspace -> 64;         ! Used temporarily by "oops" routine
0366   
0367  Global held_back_mode;               ! Flag: is there some input from last time
0368  Global hb_wn;                        ! left over?  (And a save value for wn.)
0369                                       ! (Used for full stops and "then".)
0370  ! ----------------------------------------------------------------------------
0371  Array PowersOfTwo_TB                 ! Used in converting case numbers to
0372    --> $$100000000000                 ! case bitmaps
0373        $$010000000000
0374        $$001000000000
0375        $$000100000000
0376        $$000010000000
0377        $$000001000000
0378        $$000000100000
0379        $$000000010000
0380        $$000000001000
0381        $$000000000100
0382        $$000000000010
0383        $$000000000001;
0384  ! ============================================================================
0385   
0386   
0387  ! ============================================================================
0388  !  Constants, and one variable, needed for the language definition file
0389  ! ----------------------------------------------------------------------------
0390  Constant POSSESS_PK  = $100;
0391  Constant DEFART_PK   = $101;
0392  Constant INDEFART_PK = $102;
0393  Global short_name_case;
0394  ! ----------------------------------------------------------------------------
0395  Include "language__";                !  The natural language definition,
0396                                       !  whose filename is taken from the ICL
0397                                       !  language_name variable
0398  ! ----------------------------------------------------------------------------
0399  #ifndef LanguageCases;
0400  Constant LanguageCases = 1;
0401  #endif;
0402  ! ------------------------------------------------------------------------------
0403  !   Pronouns support for the cruder (library 6/2 and earlier) version:
0404  !   only needed in English
0405  ! ------------------------------------------------------------------------------
0406  #ifdef EnglishNaturalLanguage;
0407  Global itobj = NULL;                 ! The object which is currently "it"
0408  Global himobj = NULL;                ! The object which is currently "him"
0409  Global herobj = NULL;                ! The object which is currently "her"
0410   
0411  Global old_itobj = NULL;             ! The object which is currently "it"
0412  Global old_himobj = NULL;            ! The object which is currently "him"
0413  Global old_herobj = NULL;            ! The object which is currently "her"
0414  #endif;
0415  ! ============================================================================
0416   
0417   
0418  ! ============================================================================
0419  ! "Darkness" is not really a place: but it has to be an object so that the
0420  !  location-name on the status line can be "Darkness".
0421  ! ----------------------------------------------------------------------------
0422  Object thedark "(darkness object)"
0423    with initial 0,
0424         short_name DARKNESS__TX,
0425         description
0426         [;  return L__M(##Miscellany, 17);
0427         ];


Last updated 27 February 2004. This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation. Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.