- Arguments: None
- Return: TRUE if objects found, FALSE if no objects found
12.1 Introduction
After finding the best syntax entry and any local objects to represent missing objects in the given command, SNARF-OBJECTS looks for the objects mentioned in the direct and indirect object clauses by calling two other routines on each clause:
- SNARFEM to find all the objects mentioned in the noun clause
- BUT-MERGE to remove all the exception objects not wanted by the user
The matched objects have their numbers stored into the appropriate tables, P-PRSO and P-PRSI.
12.2 Setting up Routines
SNARF-OBJECT simply sets up the variables needed by SNARFEM: start and end addresses of direct object clause and address of table to store extracted objects, P-PRSO. After calling SNARFEM, BUT-MERGE is called to remove any exception objects from BUTTABLE if any exists. This is repeated using the indirect object clause and P-PRSI. If there is only one object in P-PRSI and there are exception objects, SNARF-OBJECT assumes the exception objects will apply to the P-PRSO and call BUT-MERGE again on P-PRSO. For example, the command:
CUT ALL EXCEPT NEWSPAPER
is interpreted as multiple CUT commands on all the local objects except the newspaper. Similarly, the command:
ATTACK ALL PIRATES WITH ALL GUNS EXCEPT RIFLE
has the RIFLE object removed from the indirect objects referenced by ALL GUNS. However, the following command:
EAT ALL FRUITS WITH FORK EXCEPT APPLE
has the EXCEPT object applied to the direct objects this time as trying to apply it to the indirect objects could actually eliminate the only object in the indirect clause and generate an error.
12.3 SNARFEM: Looking for Groups of Objects
- Arguments: Start address to noun clause, End address to noun clause, Address to object table
- Return: True if objects extracted, False if no objects extracted
SNARFEM searches the noun clause for adjectives, nouns, and quantity (like ALL or ONE) tokens that describe one object or a single group of objects. Any found adjectives or nouns will have their values saved in the global variables P-ADJ and P-NAM respectively. If multiple adjectives or nouns are given, then only the most recent ones are saved in those variables. Any other tokens like conjunctions, exceptions (like BUT), or different quantity tokens indicate no more tokens to describe an object and triggers GET-OBJECT to be called which matches a local object with the given adjective and noun. Quantity tokens change how many objects are matched by GET-OBJECT by changing GETFLAGS. Exception tokens change where GET-OBJECT saves those matched objects. Details are below:
Token
|
Action
|
ALL
|
Set P-GETFLAGS to $01 (ALL mode)
|
ALL + OF
|
Set P-GETFLAGS to $01 (ALL mode) and skip over OF token
|
BUT or EXCEPT
|
If BUT table not being used, then call GET-OBJECT with TBL and switch to BUT table for subsequent storage. Otherwise, call GET-OBJECT with BUT.
|
A or ONE (no adjective set)
|
Set P-GETFLAGS to $02 (ONE mode)
|
A + OF or ONE + OF
(no adjective set)
|
Set P-GETFLAGS to $02 (ONE mode) and skip over OF token
|
A or ONE
(adjective already set)
|
Copy ONEOBJ into NAM. Call GET-OBJECT with the currently used table (TBL or BUT).
|
AND or “,”
|
Call GET-OBJECT with the currently used table (TBL or BUT)
|
AND or “,” + AND or ”,”
|
Ignore first conjunction token and continue processing
|
Buzzwords
|
Skip over this token
|
OF
(ALL, A, or ONE not given)
|
Set P-GETFLAGS to $04 (INHIBIT mode). Ignore this object as it is an error in syntax. Of note, PARSER already ignores any adjective or noun with “OF” at the start of a clause.
|
Adjective
|
Set ADJ to adjective value and Dictionary address of adjective into ADJN
|
Noun
|
Set Dictionary address of noun into NAM and ONEOBJ (just in case)
|
All other tokens
|
Skip over this token
|
No more tokens
|
Call GET-OBJECT with the currently used table (TBL or BUT)
|
For example, ALL OF THE CANDLES is the treated the same as ALL CANDLES. Also, A BLUE CARD AND A RED ONE is interpreted as A BLUE CARD AND A RED CARD with ONE referring to the just given noun CARD. ONE OF THE FLOWERS is seen as ONE FLOWERS.
If BUT or EXCEPT have not been given, any numbers for found objects will be saved in table found in the third argument. Once BUT or EXCEPT have been given, all found objects will be saved in BUT table.
12.4 BUT-MERGE
- Arguments: Address to object table
- Return: P-MERGE (address to merged object table)
This routine copies the objects in the given table into the MERGE table but skips over any objects in an exception (BUTS) table. It uses ZMEMQ to see if the given object is in BUTS. While the routine returns to address to the MERGE table. It will also put the address of the given object table into MERGE.
12.5 Getting Object Numbers for each Object with GET-OBJECT
- Arguments: Address to Object table, Verbose flag
- Return: TRUE if successful in getting appropriate number of object, FALSE for any error
GET-OBJECT tries to find a local object that matches the given identifiers (adjective, noun, and GWIMBIT) and stores that object number in the given object table. It will limit the matched objects depending on what GETFLAGS mode (default, ALL, ONE, or INHIBIT) is set by SNARFEM. SLOCBITS is first set to #FFFF (all flags set) to ensure the greatest chance of matching an object to the identifiers. If a clause’s SLOCBITS is set to a non-zero value from the matching syntax and the match mode is ALL, then that clause’s SLOCBITS is used.
GET-OBJECT requires that a noun is at least given in the command. If there is no noun, then the adjective will be used as a noun if possible. For example, “gold” can be an adjective or a noun like in “piece of gold”. If the adjective cannot be a noun, the routine will display a missing noun error and quit. Now, GET-OBJECT will look for objects in the WINNER and current location (if lit) using DO-SL. Any found objects are saved into the given object table. The processing of the objects depends on the mode:
- ALL: Search using DO-SL and return true
- INHIBIT: Return true
- ONE: Search using DO-SL or GLOBAL-CHECK found:
- 0 objects (using DO-SL): Search again using GLOBAL-CHECK
- 0 objects (using GLOBAL-CHECK): Give a CAN’T SEE error and return false.
- 1 object: Return true.
- >1 objects: Randomly pick one object and move it to the top of the table. Set the number of objects to 1. Return true.
- Default: Search using DO-SL or GLOBAL-CHECK found:
- 0 objects (using DO-SL): Search again using GLOBAL-CHECK
- 0 objects (using GLOBAL-CHECK): Give a CAN’T SEE error and return false.
- 1 object: Return true.
- >1 objects: Restore SLOCBITS from matched syntax entry. Search again with same method:
- 0 or >1 objects: Create an orphaned command by setting the ambiguous variables (AADJ, ANAM, and OFLAG) and call OPRHAN (Initial search had >1 but second search had 0 or >1 objects matched which is an ambiguous situation.) Return false.
- 1 object: Return true.
The identifiers, ADJ and NAM, are always cleared after GET-OBJECT is called except if in INHIBIT mode. If a correct number of objects is found, then the routine also restores the SLOCBITS to what is listed in the matching syntax.
No comments:
Post a Comment