Prev: 26116 Up: Map Next: 26437
26217: Parser: Match Input Word
Split the command into words and look each one up in the vocabulary.
Blank the four-character word buffer.
Parser_MatchInputWord 26217 LD DE,25246 Start at the word buffer (FourLetterBuffer).
26220 LD B,4 A word is at most four letters.
26222 LD A,32 Pad the typed word with spaces.
Parser_MatchInputWord_Loop1 26224 LD (DE),A Write spaces through the word buffer.
26225 INC DE
26226 DJNZ Parser_MatchInputWord_Loop1
26228 XOR A Jump to Handler_UnknownWord when no token slots remain.
26229 OR C
26230 JP Z,Handler_UnknownWord Jump to Handler_UnknownWord when the command has ended.
26233 LD A,(HL) Read the next character of the command.
26234 CP 13 Jump to Handler_UnknownWord when ENTER ends the command.
26236 JP Z,Handler_UnknownWord
Copy the next word, up to 4 characters, stopping at a space, a comma or ENTER.
26239 LD B,4 Keep at most four letters of this word.
26241 LD DE,25246 Point at the word buffer again.
Parser_MatchInputWord_Loop2 26244 LD A,(HL) Jump to Parser_MatchInputWord_Step1 when the character is ENTER.
26245 CP 13
26247 JR Z,Parser_MatchInputWord_Step1
26249 CP 32 Jump to Parser_MatchInputWord_Loop4 when the character is a space or a comma.
26251 JR Z,Parser_MatchInputWord_Loop4
26253 CP 44
26255 JR Z,Parser_MatchInputWord_Loop4
26257 LD (DE),A Copy the character into the word buffer and advance both pointers.
26258 INC HL
26259 INC DE
26260 DJNZ Parser_MatchInputWord_Loop2
A longer word is skipped up to the next delimiter.
Parser_MatchInputWord_Loop3 26262 LD A,(HL) Jump to Parser_MatchInputWord_Step1 on ENTER.
26263 CP 13
26265 JR Z,Parser_MatchInputWord_Step1
26267 CP 32 Jump to Parser_MatchInputWord_Loop4 on a space or a comma.
26269 JR Z,Parser_MatchInputWord_Loop4
26271 CP 44
26273 JR Z,Parser_MatchInputWord_Loop4
26275 INC HL Skip this character and keep looking for a delimiter.
26276 JR Parser_MatchInputWord_Loop3
Parser_MatchInputWord_Loop4 26278 INC HL Skip consecutive spaces.
26279 LD A,(HL)
26280 CP 32
26282 JR Z,Parser_MatchInputWord_Loop4
26284 CP 44 Jump back to Parser_MatchInputWord_Loop4 when that character is a comma (44).
26286 JR Z,Parser_MatchInputWord_Loop4
Ignore the word "THE ".
Parser_MatchInputWord_Step1 26288 EXX Compare the word with "THE " without losing the command pointer.
26289 LD HL,25319
26292 LD DE,25246
26295 LD B,4
Parser_MatchInputWord_Loop5 26297 LD A,(DE) Match the four letters of "THE ".
26298 CP (HL)
26299 JR NZ,Parser_MatchInputWord_Step2
26301 INC DE
26302 INC HL
26303 DJNZ Parser_MatchInputWord_Loop5
Parser_MatchInputWord_Step2 26305 EXX Jump back to Parser_MatchInputWord when the word was THE, so it is not tokenised.
26306 JR Z,Parser_MatchInputWord
26308 DEC C
26309 EXX Search the vocabulary addressed by *Pointer_Vocabulary.
26310 LD HL,(25244)
26313 LD C,0
Look the word up in the vocabulary. A comma separates synonyms.
Parser_MatchInputWord_Loop6 26315 LD A,(HL) Read the next vocabulary letter.
26316 CP 255 Jump to Parser_MatchInputWord_Step5 when the vocabulary list ends (255).
26318 JR Z,Parser_MatchInputWord_Step5
Parser_MatchInputWord_Loop7 26320 LD DE,25246 Point at the word buffer.
26323 LD B,4 Compare four letters of this vocabulary word.
Parser_MatchInputWord_Loop8 26325 LD A,(DE) Match the typed word against this vocabulary entry.
26326 CP (HL)
26327 JR NZ,Parser_MatchInputWord_Step3
26329 INC DE
26330 INC HL
26331 DJNZ Parser_MatchInputWord_Loop8
Word matched. Store its vocabulary index in the token buffer and parse the next word.
26333 EXX Store this vocabulary number as the current word's token.
26334 LD A,9
26336 SUB C
26337 EXX
26338 LD D,0
26340 LD E,A
26341 LD HL,25233
26344 ADD HL,DE
26345 LD (HL),C
26346 EXX
26347 JP Parser_MatchInputWord Jump to Parser_MatchInputWord to read the next word.
This vocabulary entry did not match. Try a synonym after a comma, else the next entry.
Parser_MatchInputWord_Step3 26350 LD E,B Skip the letters left in a word that did not match.
26351 LD D,0
26353 ADD HL,DE
26354 LD A,(HL) Read the byte that follows this vocabulary word.
26355 CP 44 A comma marks another synonym of the same word.
26357 JR NZ,Parser_MatchInputWord_Step4
26359 INC HL Step past that comma.
26360 JR Parser_MatchInputWord_Loop7 Jump to Parser_MatchInputWord_Loop7 to match this synonym.
Parser_MatchInputWord_Step4 26362 INC C Try the next vocabulary word.
26363 JR Parser_MatchInputWord_Loop6 Jump to Parser_MatchInputWord_Loop6.
The word is not in the vocabulary, so quote it and ask again.
Parser_MatchInputWord_Step5 26365 EXX Find the unknown word in the command buffer.
26366 LD A,10
26368 SUB C
26369 LD C,A
26370 LD HL,25183
Parser_MatchInputWord_Loop9 26373 DEC C Step back to the previous word of the command.
26374 JR Z,Parser_MatchInputWord_Step6 This is the word the game could not recognise.
Parser_MatchInputWord_Loop10 26376 LD A,(HL) Find the end of the previous word.
26377 CP 32
26379 JR Z,Parser_MatchInputWord_Loop11
26381 CP 44
26383 JR Z,Parser_MatchInputWord_Loop11
26385 INC HL
26386 JR Parser_MatchInputWord_Loop10
Parser_MatchInputWord_Loop11 26388 INC HL Skip the gap after that word.
26389 LD A,(HL)
26390 CP 32
26392 JR Z,Parser_MatchInputWord_Loop11
26394 CP 44 Jump back to Parser_MatchInputWord_Loop11 when that character is a comma (44).
26396 JR Z,Parser_MatchInputWord_Loop11
26398 JR Parser_MatchInputWord_Loop9 Jump back to Parser_MatchInputWord_Loop9 to count back another word.
Parser_MatchInputWord_Step6 26400 PUSH HL Remember where the unknown word starts.
Print "I don't know the word:-".
26401 LD HL,25344 Print "I don't know the word:-".
26404 CALL PrintStringAndANewline
26407 POP HL Restore the start of the unknown word.
26408 LD A,34 Print a quotation mark before the unknown word.
26410 CALL PrintCharacter
Parser_MatchInputWord_Loop12 26413 LD A,(HL) Print the characters of the unknown word.
26414 CP 33
26416 JR C,Parser_MatchInputWord_Step7
26418 INC HL
26419 CALL PrintCharacter
26422 JR Parser_MatchInputWord_Loop12
Parser_MatchInputWord_Step7 26424 LD A,34 Close the quotation.
26426 CALL PrintCharacter
Print ".".
26429 LD HL,25707 Print ".".
26432 CALL PrintStringAndANewline
26435 JR Handler_UnknownWord_Step1 Jump to Handler_UnknownWord_Step1 to ask for another command.
Prev: 26116 Up: Map Next: 26437