Sunday, April 21, 2019

Chapter 11. SYNTAX-CHECK: Find Correct Syntax Entry

  • Arguments: None
  • Return: TRUE if syntax matched, Syntax number if matched using GWIM, or FALSE for all errors or orphaned commands

11.1 Introduction

Given the verb, any prepositions, and any direct and indirect clauses, the game will need to see which valid syntax structure for the given verb best matches. Different usages of the same verb can require different prepositions and noun clauses (for example: TAKE LETTER, TAKE LETTER FROM MAILBOX, TAKE LETTER TO BOB). These combinations are stored as syntax entries. SYNTAX-CHECK will attempt to find the best match. If no perfect match can be found, GWIM is called to try to replace any needed missing objects. If that also fails to completely match a syntax entry, an orphan command will be created with ORPHAN.  

11.2 Hierarchy of Matching

SYNTAX-CHECK will try to match the command’s combination of verb, prepositions, and object clauses with one of the verb’s syntax entries. If it cannot find a perfect match because of missing information, it will return the best fitting entry based upon a specific hierarchy.
First, SYNTAX-CHECK will check if a verb is given. If not, then show an missing verb error and return FALSE. Up to 2 noun clauses are allowed in a syntax entry. If SYNTAX-CHECK finds a complete match as it loops through all the verb’s syntax entries, it will return that syntax entry’s action number.

11.3 GWIM (Get What I Mean)

  • Arguments: GWIMBIT number, LOC byte
  • Return: Object number if only 1 match, False if no or more than 1 object matched
If there is no complete match, SYNTAX-CHECK will call GWIM to try to match any missing object clauses with a local object to create a complete match, favoring a missing direct object clause over indirect object. For example, the command IGNITE PAPER would typically cause an error as the game does not know what object to use to ignite the paper (the indirect object clause is missing). GWIM uses GET-OBJECT to search for a local object that has a specific attribute flag (GWIMBIT) set and returns that object. In that example, the GWIMBIT would be the attribute to indicate an object is a source of fire. If a local object was a TORCH and it was on fire, then GWIM would display the clarification and return TORCH:

IGNITE PAPER
[with the torch]

GWIM first checks if the passed GWIMBIT is the RMUNGBIT (AKA KLUDGEBIT). If so, the ROOMS object is returned. After setting the global SLOCBITS and GWIMBIT variables and resetting the number of objects in the MERGE table, GET-OBJECT will try to match any object in the current location with a GWIMBIT set. If none or more than 1 object is found, then return false. If only 1 object is matched, then return that object. Also, GWIM will display a small amount of text in parentheses or brackets to describe which object was matched. It may also have additional text to clarify the matched objects (for example, if it is in your hand).

11.4 ORPHAN: Creating an Orphaned Command

  • Arguments: Address of syntax entry with missing direct object, Address of syntax entry with missing indirect object
  • Return: True
If a the command given or completed by using GWIM does not completely match any valid syntax entries, SYNTAX-CHECK will call ORPHAN to setup an orphaned command. It is also called by GET-OBJECT (described later) if too many objects match the given adjective and noun in a clause. ORPHAN will first copy the data from ITBL to OTBL. If an indirect object clause is given (possibly has ambiguous words), the indirect object tokens from LEXV are appended into OCLAUSE. Then, if a direct object clause is given (possibly has ambiguous words), the direct object tokens from LEXV are appended into OCLAUSE. So the indirect object tokens are placed before the direct object tokens in OCLAUSE. When called by SYNTAX-CHECK, it also copies the corresponding preposition number (if any) for the missing noun clauses into the OTBL. ORPHAN then stores $01 as the start address of the missing or ambiguous noun clauses in the OTBL to indicate that clause has a missing or ambiguous word. Finally, SYNTAX-CHECK will then set the O-FLAG and offer clarifying information for the player to help supply the missing information.

Possible Outcomes:
Syntax Entry Command
0 object clauses
1 object clause
2 object clauses
0 object clauses
All prepositions should be all blank. Return Action number
If DO preposition matches or command preposition is missing, then DO Is missing. Save syntax entry address in DO missing var.
If DO preposition matches or command preposition is missing, then DO is missing. Save syntax entry address in DO missing var.
1 object clause
All prepositions should be all blank. Return Action number
If DO preposition matches and indirect object preposition is blank, then get Action number
If DO preposition matches, then IO is missing. Save syntax entry address in IO missing var.
2 object clauses
All prepositions should be all blank. Return Action number
If DO preposition matches and indirect object preposition is blank, then get Action number
If direct and indirect object prepositions match, then get Action number

11.5 Update: SYNTAX-CHECK

No major changes were made in SYNTAX-CHECK except for a check on the number of noun clauses in the input. If it was greater than the number in the syntax entry, then it would bypass checking for orphaned clauses as it isn’t possible. Also, the error messaging was more specific depending on what piece of information was missing such as using “WHO” or “WHERE” when appropriate and if the WINNER Is the PLAYER or a different actor. Some games check for specific verbs that will not generate an orphaned command.
Mini-Zork did use a new compact format for the syntax entries that was also used in Sherlock. No other released Infocom game used it. The size of the entry depended on the number of objects in the entry. The number of objects is stored in the highest 2 bits of byte 1. The preposition number for the direct object is reduced by $C0 and stored in the lower 6 bits of byte 1. The preposition number for the indirect object is also reduced by $C0 and stored in the lower 6 bits of byte 5. However, the top 2 bits are not used in byte 5. The syntax token byte is composed to flags that refer to the LOC tokens referred earlier.
The structure of the syntax entries for no objects is:
Byte 1
Byte 2
2 high bits = number of object clauses
6 low bits = Preposition number for direct object
Action number
The structure of the syntax entries with only direct objects is:
Byte 1
Byte 2
Byte 3
Byte 4
2 high bits = number of object clauses
6 low bits = Preposition number for direct object
Action number
GWIMBIT number for direct object
LOC byte for direct object
The structure of the syntax entries with direct and indirect objects is:
Byte 1
Byte 2
Byte 3
Byte 4
Byte 5
Byte 6
Byte 7
2 high bits = number of object clauses
6 low bits = Preposition number for direct object
Action number
GWIMBIT number for direct object
LOC byte for direct object
Prep number for indirect object
GWIMBIT number for indirect object
LOC byte for direct object
These variable sized entries help eliminate any wasted space in the syntax entry blocks. SYNTAX-CHECK and SYNTAX-FOUND were adjusted to use this different format.

11.6 Update: New versions of GWIM

Many games used modified GWIM routines that would add extra clarifying text such as “of”, “at” or “in” when commenting to the user about an object matched because of a command with a specific preposition. The Witness would use a special string to refer to an object matched by GWIM instead of the standard object name. For example, GWIM will use “Asian man” preceded by “the” instead of the object’s name, “Mr. Phong”. Trinity introduced an initial check of the GWIMBIT in the IT-OBJECT if it is set to an object. The routine will return what the object that is referenced by IT-OBJECT.

11.7 Update: New versions of ORPHAN

HGTG introduce a new method for handling orphaned commands with the introduction of the game’s new CLAUSE-COPY (see above). For its ORPHAN routine, it made sure OCLAUSE was cleared if P-MERGED is also clear and also copied over VTBL to OVTBL.
Mini-Zork has a modified ORPHAN because it uses a modified syntax entry format. Instead of manually getting the preposition number from the syntax entry, Mini-Zork calls a separate routine that extracts is from the modified syntax entry format. Version 4 and 5 games could call CLAUSE-COPY with more arguments and needed fewer global variables. So CC-TBL was not needed anymore. Version 5 games used the same routine as the Version 4 games but using the COPY-TABLE command that replaced the manual copying loop in ORPHAN.

Bureaucracy uses the same routine as AMFV except it copies the object clauses into separate token buffers, OCLAUSE for the direct object tokens and IClause for the indirect object tokens.

No comments:

Post a Comment