Saturday, February 23, 2019

Chapter 7. PARSER: How Now Brown Cow (Part 2) - Scanning Tokens

 Start of PARSER: Where is the command?

PARSER was able to understand single commands or multiple commands separated by “.” or THEN by parsing them individually. It first decides if the next command should come from the previously given input by seeing if P-CONT is set. This variable contains the starting location of the next command’s first token from the previous input. This is set by seeing if more tokens exist after a complete command is parsed. If P-CONT is clear, PARSER then asks for new input from the user by printing “>” character and calling the READ opcode.

7.7 Now, Traverse the Tokens…

Because of the structure of accepted commands, PARSER can search for a command in an efficient manner. It will walk through the tokens and look for ones with specific parts of speech. If a noun clause is found, PARSER will call another routine, CLAUSE, to find the start and end tokens for the direct object clause. If no error is returned by CLAUSE, PARSER will continue checking tokens and look for another noun clause (indirect object clause) or end-of-command token. The order for checking tokens is:
  1. 1. Invalid Token

All valid tokens have an address to their associated entry in the vocabulary. Any invalid or unmatch tokens are given an address of $00. If this is found, an unknown-word error message will be printed and FALSE returned.
  1. 2. End-of-Command Token

An end-of-command token (THEN or “.”) will stop the loop and jump to the post-looping processing. If there are more tokens, PARSER will save the position of this next token which PARSER will use for the next command.
  1. 3. Direction Token

This is the only verb with its own specific check in PARSER since it is the most common command given. A direction token has an associated direction value which is the property number for a room’s exits in that direction. There are 4 special scenarios where this direction value is saved and the loop is stopped:

  1. 1. This is a 1 token command, just the direction is given.
  2. 2. This is a 2 token command and the verb GO was already given (as in “GO EAST”).
  3. 3. There are more tokens after the direction, and the next token is a end-of-command token.
  4. 4. There are more tokens after the direction, and the next token is a conjunction token (AND or “,”). If so, the conjunction token is changed to “then” to indicate a new command. So a series of direction commands separated by commas or “and” become separate commands.
PRSA is set to GO (if not already done). PRSO is later set to the direction value.  
  1. 4. Verb Token

If a verb token is found, PARSER checks if a verb has already been a found. A command cannot have two verbs. If no verb has already been found, this verb’s verb number and address to a verb table that has the 4 byte token data are stored in words 0 and 1 of ITBL. If a verb has already be found, PARSER will see if it the word could also refer to a different valid part of speech.
  1. 5. Preposition, Quantity, Adjective, and Noun Tokens

Any of the above tokens indicates a noun clause is starting. The number of noun clauses variable is incremented. A separate routine (CLAUSE) will then find the end of the noun clause and store the start and end addresses in ITBL. CLAUSE then returns the start address of any remaining tokens PARSER should process. There are several exceptions where CLAUSE is not execute:

  1. 1. If the matched adjective or noun is followed by OF, PARSER will ignore the adjective and noun and use the token after OF for the start of the noun clause. This new token will be matched on a subsequent loop.
  2. 2. If there are no more tokens or an end-of-command token is next after the matched preposition and less than 2 noun clauses have been found, the preposition address and value information will be save into ITBL (Word 2 and 3).
  3. 3. If there are already 2 noun clauses, a "Too many noun clauses??" error is given. PARSER will then return with FALSE.
  1. 6. Special Token

Any remaining special tokens that do not affect the syntax or objects requested will be ignored. This includes tokens like IS, YES, A, or THE.
  1. 7. Improper/extra tokens - Syntax Error

All other situations are a syntax error. Therefore, PARSER will display a can’t-use-the-word error and return FALSE. examples?
The first version of PARSER could understand multiple commands if they were separated by THEN or “.”. Using AND or “,” between verbs without objects like

JUMP AND LOOK

were not understood. However, commands with objects separated by AND or “,” like

OPEN MAILBOX AND GET LEAFLET

are accepted as CLAUSE would realize the AND separates two commands.

No comments:

Post a Comment