



At Start InfixInvSub (lines 1-555)
Back to List
Forward
Browsing parserm.h
0001 ! ==============================================================================
0002 ! PARSERM: Core of parser.
0003 !
0004 ! Supplied for use with Inform 6 -- Release 6/11 -- Serial number 040227
0005 !
0006 ! Copyright Graham Nelson 1993-2004 but freely usable (see manuals)
0007 !
0008 ! This file is automatically Included in your game file by "Parser".
0009 ! ------------------------------------------------------------------------------
0010 ! Inclusion of "linklpa" (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
0049 #Ifdef MODULE_MODE;
0050 Constant DEBUG;
0051 Constant Grammar__Version 2;
0052 Include "linklpa";
0053 #Endif; ! MODULE_MODE
0054
0055 ! ------------------------------------------------------------------------------
0056 ! Global variables and their associated Constant and Array declarations
0057 ! ------------------------------------------------------------------------------
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
0067 #Ifdef TARGET_ZCODE;
0068 Global top_object; ! Largest valid number of any tree object
0069 ! ### these globals are not meaningful... well, maybe standard_interpreter,
0070 ! but I'll decide that later (AP).
0071 Constant INDIV_PROP_START 64; ! Equivalent of a Glulx constant
0072
0073 #Endif; ! TARGET_ZCODE
0074
0075 Global standard_interpreter; ! The version number of the Z-Machine Standard which the
0076 ! interpreter claims to support, in form (upper byte).(lower)
0077
0078 Global undo_flag; ! Can the interpreter provide "undo"?
0079 Global just_undone; ! Can't have two successive UNDOs
0080
0081 Global transcript_mode; ! true when game scripting is on
0082
0083 #Ifdef TARGET_ZCODE;
0084 Global xcommsdir; ! true if command recording is on
0085 #Endif; ! TARGET_ZCODE
0086
0087 #Ifdef TARGET_GLULX;
0088 Constant GG_MAINWIN_ROCK 201;
0089 Constant GG_STATUSWIN_ROCK 202;
0090 Constant GG_QUOTEWIN_ROCK 203;
0091 Constant GG_SAVESTR_ROCK 301;
0092 Constant GG_SCRIPTSTR_ROCK 302;
0093 Constant GG_COMMANDWSTR_ROCK 303;
0094 Constant GG_COMMANDRSTR_ROCK 304;
0095 Constant GG_SCRIPTFREF_ROCK 401;
0096 Array gg_event --> 4;
0097 #Ifdef VN_1630;
0098 Array gg_arguments buffer 28;
0099 #Ifnot;
0100 Array gg_arguments --> 8;
0101 #Endif; ! VN_
0102 Global gg_mainwin = 0;
0103 Global gg_statuswin = 0;
0104 Global gg_quotewin = 0;
0105 Global gg_scriptfref = 0;
0106 Global gg_scriptstr = 0;
0107 Global gg_savestr = 0;
0108 Global gg_commandstr = 0;
0109 Global gg_command_reading = 0; ! true if gg_commandstr is being replayed
0110 #Endif; ! TARGET_GLULX
0111
0112 Global gg_statuswin_cursize = 0;
0113 Global gg_statuswin_size = 1;
0114
0115 ! ------------------------------------------------------------------------------
0116 ! Time and score
0117 ! (for linkage reasons, the task_* arrays are created not here but in verblib.h)
0118 ! ------------------------------------------------------------------------------
0119
0120 #Ifndef sys_statusline_flag;
0121 Global sys_statusline_flag = 0; ! non-zero if status line displays time
0122 #Endif;
0123 #Ifndef START_MOVE;
0124 Constant START_MOVE 0; ! Traditionally 0 for Infocom, 1 for Inform
0125 #Endif;
0126 Global turns = START_MOVE; ! Number of turns of play so far
0127 Global the_time = NULL; ! Current time (in minutes since midnight)
0128 Global time_rate = 1; ! How often time is updated
0129 Global time_step; ! By how much
0130
0131 #Ifndef MAX_TIMERS;
0132 Constant MAX_TIMERS 32; ! Max number timers/daemons active at once
0133 #Endif; ! MAX_TIMERS
0134 Array the_timers --> MAX_TIMERS;
0135 Global active_timers; ! Number of timers/daemons actives
0136
0137 Global score; ! The current score
0138 Global last_score; ! Score last turn (for testing for changes)
0139 Global notify_mode = true; ! Score notification
0140 Global places_score; ! Contribution to score made by visiting
0141 Global things_score; ! Contribution made by acquisition
0142
0143 ! ------------------------------------------------------------------------------
0144 ! The player
0145 ! ------------------------------------------------------------------------------
0146
0147 Global player; ! Which object the human is playing through
0148 Global deadflag; ! Normally 0, or false; 1 for dead; 2 for victorious, and
0149 ! higher numbers represent exotic forms of death
0150
0151 ! ------------------------------------------------------------------------------
0152 ! Light and room descriptions
0153 ! ------------------------------------------------------------------------------
0154
0155 Global lightflag = true; ! Is there currently light to see by?
0156 Global real_location; ! When in darkness, location = thedark
0157 ! and this holds the real location
0158 Global visibility_ceiling; ! Highest object in tree visible from the player's point of view
0159 ! (usually the room, sometimes darkness, sometimes a closed
0160 ! non-transparent container).
0161
0162 Global lookmode = 1; ! 1=standard, 2=verbose, 3=brief room descs
0163 Global print_player_flag; ! If set, print something like "(as Fred)" in room descriptions,
0164 ! to reveal whom the human is playing through
0165 Global lastdesc; ! Value of location at time of most recent room description
0166 ! printed out
0167
0168 ! ------------------------------------------------------------------------------
0169 ! List writing (style bits are defined as Constants in "verblibm.h")
0170 ! ------------------------------------------------------------------------------
0171
0172 Global c_style; ! Current list-writer style
0173 Global lt_value; ! Common value of list_together
0174 Global listing_together; ! Object number of one member of a group being listed together
0175 Global listing_size; ! Size of such a group
0176 Global wlf_indent; ! Current level of indentation printed by WriteListFrom()
0177
0178 Global inventory_stage = 1; ! 1 or 2 according to the context in which "invent" routines
0179 ! of objects are called
0180 Global inventory_style; ! List-writer style currently used while printing inventories
0181 ! ------------------------------------------------------------------------------
0182 ! Menus and printing
0183 ! ------------------------------------------------------------------------------
0184
0185 Global pretty_flag = true; ! Use character graphics, or plain text?
0186 Global menu_nesting; ! Level of nesting (0 = root menu)
0187 Global menu_item; ! These are used in communicating
0188 Global item_width = 8; ! with the menu-creating routines
0189 Global item_name = "---";
0190
0191 Global lm_n; ! Parameters used by LibraryMessages
0192 Global lm_o; ! mechanism
0193
0194 #Ifdef DEBUG;
0195 Global debug_flag; ! Bitmap of flags for tracing actions,
0196 ! calls to object routines, etc.
0197 Global x_scope_count; ! Used in printing a list of everything
0198 #Endif; ! DEBUG ! in scope
0199
0200 ! five for colour control
0201 ! see http://www.inform-fiction.org/patches/L61007.html
0202 Global clr_fg = 1; ! foreground colour
0203 Global clr_bg = 1; ! background colour
0204 Global clr_fgstatus = 1; ! foreground colour of statusline
0205 Global clr_bgstatus = 1; ! background colour of statusline
0206 Global clr_on; ! has colour been enabled by the player?
0207 Global statuswin_current; ! if writing to top window
0208
0209 Constant CLR_DEFAULT 1;
0210 Constant CLR_BLACK 2;
0211 Constant CLR_RED 3;
0212 Constant CLR_GREEN 4;
0213 Constant CLR_YELLOW 5;
0214 Constant CLR_BLUE 6;
0215 Constant CLR_MAGENTA 7;
0216 Constant CLR_CYAN 8;
0217 Constant CLR_WHITE 9;
0218 Constant CLR_PURPLE 7;
0219 Constant CLR_AZURE 8;
0220
0221 Constant WIN_ALL 0;
0222 Constant WIN_STATUS 1;
0223 Constant WIN_MAIN 2;
0224
0225 ! ------------------------------------------------------------------------------
0226 ! Action processing
0227 ! ------------------------------------------------------------------------------
0228
0229 Global action; ! Action currently being asked to perform
0230 Global inp1; ! 0 (nothing), 1 (number) or first noun
0231 Global inp2; ! 0 (nothing), 1 (number) or second noun
0232 Global noun; ! First noun or numerical value
0233 Global second; ! Second noun or numerical value
0234
0235 Global keep_silent; ! If true, attempt to perform the action silently (e.g. for
0236 ! implicit takes, implicit opening of unlocked doors)
0237
0238 Global reason_code; ! Reason for calling a "life" rule
0239 ! (an action or fake such as ##Kiss)
0240
0241 Global receive_action; ! Either ##PutOn or ##Insert, whichever is action being tried
0242 ! when an object's "before" rule is checking "Receive"
0243
0244 ! ==============================================================================
0245 ! Parser variables: first, for communication to the parser
0246 ! ------------------------------------------------------------------------------
0247
0248 Global parser_trace = 0; ! Set this to 1 to make the parser trace tokens and lines
0249 Global parser_action; ! For the use of the parser when calling
0250 Global parser_one; ! user-supplied routines
0251 Global parser_two; !
0252 Array inputobjs --> 16; ! For parser to write its results in
0253 Global parser_inflection; ! A property (usually "name") to find object names in
0254
0255 ! ------------------------------------------------------------------------------
0256 ! Parser output
0257 ! ------------------------------------------------------------------------------
0258
0259 Global actor; ! Person asked to do something
0260 Global actors_location; ! Like location, but for the actor
0261 Global meta; ! Verb is a meta-command (such as "save")
0262
0263 Array multiple_object --> 64; ! List of multiple parameters
0264 Global multiflag; ! Multiple-object flag passed to actions
0265 ! Also used to prevent misleading MULTI_PE
0266 Global toomany_flag; ! Flag for "multiple match too large"
0267 ! (e.g. if "take all" took over 100 things)
0268
0269 Global special_word; ! Dictionary address for "special" token
0270 Global special_number; ! Number typed for "special" token
0271 Global parsed_number; ! For user-supplied parsing routines
0272 Global consult_from; ! Word that a "consult" topic starts on
0273 Global consult_words; ! ...and number of words in topic
0274
0275 ! ------------------------------------------------------------------------------
0276 ! Implicit taking
0277 ! ------------------------------------------------------------------------------
0278
0279 Global notheld_mode; ! To do with implicit taking
0280 Global onotheld_mode; ! "old copy of notheld_mode", ditto
0281 Global not_holding; ! Object to be automatically taken as an
0282 ! implicit command
0283 Array kept_results --> 16; ! Delayed command (while the take happens)
0284
0285 ! ------------------------------------------------------------------------------
0286 ! Error numbers when parsing a grammar line
0287 ! ------------------------------------------------------------------------------
0288
0289 Global etype; ! Error number on current line
0290 Global best_etype; ! Preferred error number so far
0291 Global nextbest_etype; ! Preferred one, if ASKSCOPE_PE disallowed
0292
0293 Constant STUCK_PE = 1;
0294 Constant UPTO_PE = 2;
0295 Constant NUMBER_PE = 3;
0296 Constant CANTSEE_PE = 4;
0297 Constant TOOLIT_PE = 5;
0298 Constant NOTHELD_PE = 6;
0299 Constant MULTI_PE = 7;
0300 Constant MMULTI_PE = 8;
0301 Constant VAGUE_PE = 9;
0302 Constant EXCEPT_PE = 10;
0303 Constant ANIMA_PE = 11;
0304 Constant VERB_PE = 12;
0305 Constant SCENERY_PE = 13;
0306 Constant ITGONE_PE = 14;
0307 Constant JUNKAFTER_PE = 15;
0308 Constant TOOFEW_PE = 16;
0309 Constant NOTHING_PE = 17;
0310 Constant ASKSCOPE_PE = 18;
0311
0312 ! ------------------------------------------------------------------------------
0313 ! Pattern-matching against a single grammar line
0314 ! ------------------------------------------------------------------------------
0315
0316 Array pattern --> 32; ! For the current pattern match
0317 Global pcount; ! and a marker within it
0318 Array pattern2 --> 32; ! And another, which stores the best match
0319 Global pcount2; ! so far
0320 Constant PATTERN_NULL = $ffff; ! Entry for a token producing no text
0321
0322 Array line_ttype-->32; ! For storing an analysed grammar line
0323 Array line_tdata-->32;
0324 Array line_token-->32;
0325
0326 Global parameters; ! Parameters (objects) entered so far
0327 Global nsns; ! Number of special_numbers entered so far
0328 Global special_number1; ! First number, if one was typed
0329 Global special_number2; ! Second number, if two were typed
0330
0331 ! ------------------------------------------------------------------------------
0332 ! Inferences and looking ahead
0333 ! ------------------------------------------------------------------------------
0334
0335 Global params_wanted; ! Number of parameters needed (which may change in parsing)
0336
0337 Global inferfrom; ! The point from which the rest of the command must be inferred
0338 Global inferword; ! And the preposition inferred
0339 Global dont_infer; ! Another dull flag
0340
0341 Global action_to_be; ! (If the current line were accepted.)
0342 Global action_reversed; ! (Parameters would be reversed in order.)
0343 Global advance_warning; ! What a later-named thing will be
0344
0345 ! ------------------------------------------------------------------------------
0346 ! At the level of individual tokens now
0347 ! ------------------------------------------------------------------------------
0348
0349 Global found_ttype; ! Used to break up tokens into type
0350 Global found_tdata; ! and data (by AnalyseToken)
0351 Global token_filter; ! For noun filtering by user routines
0352
0353 Global length_of_noun; ! Set by NounDomain to no of words in noun
0354
0355 #Ifdef TARGET_ZCODE;
0356 Constant REPARSE_CODE = 10000; ! Signals "reparse the text" as a reply from NounDomain
0357 #Ifnot; ! TARGET_GLULX
0358 Constant REPARSE_CODE = $40000000; ! The parser rather gunkily adds addresses to REPARSE_CODE for
0359 ! some purposes. And expects the result to be greater than
0360 ! REPARSE_CODE (signed comparison). So Glulx Inform is limited
0361 ! to a single gigabyte of storage, for the moment.
0362 #Endif; ! TARGET_
0363
0364 Global lookahead; ! The token after the one now being matched
0365
0366 Global multi_mode; ! Multiple mode
0367 Global multi_wanted; ! Number of things needed in multitude
0368 Global multi_had; ! Number of things actually found
0369 Global multi_context; ! What token the multi-obj was accepted for
0370
0371 Global indef_mode; ! "Indefinite" mode - ie, "take a brick"
0372 ! is in this mode
0373 Global indef_type; ! Bit-map holding types of specification
0374 Global indef_wanted; ! Number of items wanted (100 for all)
0375 Global indef_guess_p; ! Plural-guessing flag
0376 Global indef_owner; ! Object which must hold these items
0377 Global indef_cases; ! Possible gender and numbers of them
0378 Global indef_possambig; ! Has a possibly dangerous assumption
0379 ! been made about meaning of a descriptor?
0380 Global indef_nspec_at; ! Word at which a number like "two" was parsed
0381 ! (for backtracking)
0382 Global allow_plurals; ! Whether plurals presently allowed or not
0383
0384 Global take_all_rule; ! Slightly different rules apply to "take all" than other uses
0385 ! of multiple objects, to make adjudication produce more
0386 ! pragmatically useful results
0387 ! (Not a flag: possible values 0, 1, 2)
0388
0389 Global dict_flags_of_noun; ! Of the noun currently being parsed
0390 ! (a bitmap in #dict_par1 format)
0391 Global pronoun_word; ! Records which pronoun ("it", "them", ...) caused an error
0392 Global pronoun_obj; ! And what obj it was thought to refer to
0393 Global pronoun__word; ! Saved value
0394 Global pronoun__obj; ! Saved value
0395
0396 ! ------------------------------------------------------------------------------
0397 ! Searching through scope and parsing "scope=Routine" grammar tokens
0398 ! ------------------------------------------------------------------------------
0399
0400 Constant PARSING_REASON = 0; ! Possible reasons for searching scope
0401 Constant TALKING_REASON = 1;
0402 Constant EACH_TURN_REASON = 2;
0403 Constant REACT_BEFORE_REASON = 3;
0404 Constant REACT_AFTER_REASON = 4;
0405 Constant LOOPOVERSCOPE_REASON = 5;
0406 Constant TESTSCOPE_REASON = 6;
0407
0408 Global scope_reason = PARSING_REASON; ! Current reason for searching scope
0409
0410 Global scope_token; ! For "scope=Routine" grammar tokens
0411 Global scope_error;
0412 Global scope_stage; ! 1, 2 then 3
0413
0414 Global ats_flag = 0; ! For AddToScope routines
0415 Global ats_hls; !
0416
0417 Global placed_in_flag; ! To do with PlaceInScope
0418
0419 ! ------------------------------------------------------------------------------
0420 ! The match list of candidate objects for a given token
0421 ! ------------------------------------------------------------------------------
0422
0423 Constant MATCH_LIST_SIZE = 128;
0424 Array match_list --> 64; ! An array of matched objects so far
0425 Array match_classes --> 64; ! An array of equivalence classes for them
0426 Array match_scores --> 64; ! An array of match scores for them
0427 Global number_matched; ! How many items in it? (0 means none)
0428 Global number_of_classes; ! How many equivalence classes?
0429 Global match_length; ! How many words long are these matches?
0430 Global match_from; ! At what word of the input do they begin?
0431 Global bestguess_score; ! What did the best-guess object score?
0432
0433 ! ------------------------------------------------------------------------------
0434 ! Low level textual manipulation
0435 ! ------------------------------------------------------------------------------
0436
0437 #Ifdef TARGET_ZCODE;
0438
0439 Constant INPUT_BUFFER_LEN = 120; ! Length of buffer array (although we leave an extra byte
0440 ! to allow for interpreter bugs)
0441
0442 Array buffer -> 123; ! Buffer for parsing main line of input
0443 #Ifdef VN_1630;
0444 Array parse buffer 63; ! Parse table mirroring it
0445 Array parse2 buffer 63; !
0446 #Ifnot;
0447 Array parse -> 65; ! Parse table mirroring it
0448 Array parse2 -> 65; !
0449 #Endif; ! VN_
0450 Array buffer2 -> 123; ! Buffers for supplementary questions
0451 Array buffer3 -> 123; ! Buffer retaining input for "again"
0452
0453 #Ifnot; ! TARGET_GLULX
0454
0455 Constant INPUT_BUFFER_LEN = 260; ! No extra byte necessary
0456 Constant MAX_BUFFER_WORDS = 20;
0457 Constant PARSE_BUFFER_LEN = 244; ! 4 + MAX_BUFFER_WORDS*4;
0458
0459 #Ifdef VN_1630;
0460 Array buffer buffer INPUT_BUFFER_LEN;
0461 Array buffer2 buffer INPUT_BUFFER_LEN;
0462 Array buffer3 buffer INPUT_BUFFER_LEN;
0463 #Ifnot;
0464 Array buffer -> INPUT_BUFFER_LEN;
0465 Array buffer2 -> INPUT_BUFFER_LEN;
0466 Array buffer3 -> INPUT_BUFFER_LEN;
0467 #Endif;
0468 Array parse --> PARSE_BUFFER_LEN/WORDSIZE;
0469 Array parse2 --> PARSE_BUFFER_LEN/WORDSIZE;
0470
0471 #Endif; ! TARGET_
0472
0473 Constant comma_word = 'comma,'; ! An "untypeable word" used to substitute
0474 ! for commas in parse buffers
0475
0476 Global wn; ! Word number within "parse" (from 1)
0477 Global num_words; ! Number of words typed
0478 Global verb_word; ! Verb word (eg, take in "take all" or
0479 ! "dwarf, take all") - address in dict
0480 Global verb_wordnum; ! its number in typing order (eg, 1 or 3)
0481 Global usual_grammar_after; ! Point from which usual grammar is parsed (it may vary from the
0482 ! above if user's routines match multi-word verbs)
0483
0484 Global oops_from; ! The "first mistake" word number
0485 Global saved_oops; ! Used in working this out
0486 Array oops_workspace -> 64; ! Used temporarily by "oops" routine
0487
0488 Global held_back_mode; ! Flag: is there some input from last time
0489 Global hb_wn; ! left over? (And a save value for wn.)
0490 ! (Used for full stops and "then".)
0491
0492 ! ----------------------------------------------------------------------------
0493
0494 Array PowersOfTwo_TB ! Used in converting case numbers to case bitmaps
0495 --> $$100000000000
0496 $$010000000000
0497 $$001000000000
0498 $$000100000000
0499 $$000010000000
0500 $$000001000000
0501 $$000000100000
0502 $$000000010000
0503 $$000000001000
0504 $$000000000100
0505 $$000000000010
0506 $$000000000001;
0507
0508 ! ============================================================================
0509 ! Constants, and one variable, needed for the language definition file
0510 ! ----------------------------------------------------------------------------
0511
0512 Constant POSSESS_PK = $100;
0513 Constant DEFART_PK = $101;
0514 Constant INDEFART_PK = $102;
0515 Global short_name_case;
0516
0517 Global dict_start;
0518 Global dict_entry_size;
0519 Global dict_end;
0520
0521 ! ----------------------------------------------------------------------------
0522
0523 Include "language__"; ! The natural language definition, whose filename is taken from
0524 ! the ICL language_name variable
0525
0526 ! ----------------------------------------------------------------------------
0527
0528 #Ifndef LanguageCases;
0529 Constant LanguageCases = 1;
0530 #Endif; ! LanguageCases
0531
0532 ! ------------------------------------------------------------------------------
0533 ! Pronouns support for the cruder (library 6/2 and earlier) version:
0534 ! only needed in English
0535 ! ------------------------------------------------------------------------------
0536
0537 #Ifdef EnglishNaturalLanguage;
0538 Global itobj = NULL; ! The object which is currently "it"
0539 Global himobj = NULL; ! The object which is currently "him"
0540 Global herobj = NULL; ! The object which is currently "her"
0541
0542 Global old_itobj = NULL; ! The object which is currently "it"
0543 Global old_himobj = NULL; ! The object which is currently "him"
0544 Global old_herobj = NULL; ! The object which is currently "her"
0545 #Endif; ! EnglishNaturalLanguage
0546
0547 ! ============================================================================
0548 ! "Darkness" is not really a place: but it has to be an object so that the
0549 ! location-name on the status line can be "Darkness".
0550 ! ----------------------------------------------------------------------------
0551
0552 Object thedark "(darkness object)"
0553 with initial 0,
0554 short_name DARKNESS__TX,
0555 description [; return L__M(##Miscellany, 17); ];
Last updated 27 February 2004. The librarian in charge of this page is Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight. Please email any comments, suggestions or corrections to cedenqs@inform-fiction.org.