Prev: 49011 Up: Map Next: 49332
49112: 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 49112 LD DE,47937 Start at the word buffer (47937).
49115 LD B,4 Prepare a space and a counter of 4 characters.
49117 LD A,32
MatchInputWord_Clear 49119 LD (DE),A Write spaces through the word buffer.
49120 INC DE
49121 DJNZ MatchInputWord_Clear
49123 XOR A Jump to Handler_UnknownWord when no token slots remain, or the command has ended.
49124 OR C
49125 JP Z,Handler_UnknownWord
49128 LD A,(HL)
49129 CP 13
49131 JP Z,Handler_UnknownWord
Copy the next word, up to 4 characters, stopping at a space, a comma or ENTER.
49134 LD B,4 Copy up to 4 characters into the word buffer.
49136 LD DE,47937
MatchInputWord_Copy 49139 LD A,(HL) Jump to MatchInputWord_IgnoreThe when the character is ENTER.
49140 CP 13
49142 JR Z,MatchInputWord_IgnoreThe
49144 CP 32 Jump to MatchInputWord_Delimiter when the character is a space or a comma.
49146 JR Z,MatchInputWord_Delimiter
49148 CP 44
49150 JR Z,MatchInputWord_Delimiter
49152 LD (DE),A Copy the character into the word buffer and advance both pointers.
49153 INC HL
49154 INC DE
49155 DJNZ MatchInputWord_Copy Repeat from MatchInputWord_Copy until four characters have been copied.
A longer word is skipped up to the next delimiter.
MatchInputWord_Skip 49157 LD A,(HL) Jump to MatchInputWord_IgnoreThe on ENTER, or to MatchInputWord_Delimiter on a space or a comma.
49158 CP 13
49160 JR Z,MatchInputWord_IgnoreThe
49162 CP 32
49164 JR Z,MatchInputWord_Delimiter
49166 CP 44
49168 JR Z,MatchInputWord_Delimiter
49170 INC HL Skip this character and keep looking for a delimiter.
49171 JR MatchInputWord_Skip
MatchInputWord_Delimiter 49173 INC HL Skip consecutive spaces and commas.
49174 LD A,(HL)
49175 CP 32
49177 JR Z,MatchInputWord_Delimiter
49179 CP 44
49181 JR Z,MatchInputWord_Delimiter
Ignore the word "THE ".
MatchInputWord_IgnoreThe 49183 EXX Switch in the spare registers and point them at "THE " and the word.
49184 LD HL,47964
49187 LD DE,47937
49190 LD B,4
MatchInputWord_The 49192 LD A,(DE) Compare the four characters.
49193 CP (HL)
49194 JR NZ,MatchInputWord_AfterThe
49196 INC DE
49197 INC HL
49198 DJNZ MatchInputWord_The
MatchInputWord_AfterThe 49200 EXX Switch back to the main registers to act on the comparison.
49201 JR Z,Parser_MatchInputWord Jump back to Parser_MatchInputWord when the word was THE, so it is not tokenised.
49203 DEC C Use up one token slot.
49204 EXX
Look the word up in the vocabulary. A comma separates synonyms.
49205 LD HL,(47836) Start at the vocabulary, with the token index at zero.
49208 LD C,0
MatchInputWord_Vocabulary 49210 LD A,(HL) Jump to MatchInputWord_Unknown when the vocabulary is exhausted.
49211 CP 255
49213 JR Z,MatchInputWord_Unknown
MatchInputWord_CompareWord 49215 LD DE,47937 Compare the next vocabulary word with the word buffer.
49218 LD B,4
MatchInputWord_CompareChar 49220 LD A,(DE) Compare the next character.
49221 CP (HL)
49222 JR NZ,MatchInputWord_NextWord Jump to MatchInputWord_NextWord when it does not match.
49224 INC DE
49225 INC HL
49226 DJNZ MatchInputWord_CompareChar
49228 EXX Turn the vocabulary index into a token-slot offset.
49229 LD A,9
49231 SUB C
49232 EXX
49233 LD D,0
49235 LD E,A
49236 LD HL,47926 Store that token in its slot at 47926 and parse the next word.
49239 ADD HL,DE
49240 LD (HL),C
49241 EXX
49242 JP Parser_MatchInputWord
MatchInputWord_NextWord 49245 LD E,B Step to the end of this vocabulary word.
49246 LD D,0
49248 ADD HL,DE
49249 LD A,(HL) Jump back to MatchInputWord_CompareWord to try the synonym after a comma.
49250 CP 44
49252 JR NZ,MatchInputWord_NextEntry
49254 INC HL
49255 JR MatchInputWord_CompareWord
MatchInputWord_NextEntry 49257 INC C Try the next vocabulary word.
49258 JR MatchInputWord_Vocabulary
The word is not in the vocabulary, so quote it and ask again.
MatchInputWord_Unknown 49260 EXX Find the unknown word in the command buffer.
49261 LD A,10
49263 SUB C
49264 LD C,A
49265 LD HL,47876
MatchInputWord_SeekWord 49268 DEC C Step back through the copied word count.
49269 JR Z,MatchInputWord_PrintUnknown
MatchInputWord_FindWord 49271 LD A,(HL) Skip characters until a space or a comma.
49272 CP 32
49274 JR Z,MatchInputWord_FindDelimiter
49276 CP 44
49278 JR Z,MatchInputWord_FindDelimiter
49280 INC HL
49281 JR MatchInputWord_FindWord
MatchInputWord_FindDelimiter 49283 INC HL Skip spaces and commas, then look for the next word.
49284 LD A,(HL)
49285 CP 32
49287 JR Z,MatchInputWord_FindDelimiter
49289 CP 44
49291 JR Z,MatchInputWord_FindDelimiter
49293 JR MatchInputWord_SeekWord
MatchInputWord_PrintUnknown 49295 PUSH HL Print "I don't know the word:-".
49296 LD HL,47989
49299 CALL PrintStringAndANewline
49302 POP HL Restore the command pointer from the stack.
49303 LD A,34 Print a quote.
49305 CALL PrintCharacter
MatchInputWord_Quote 49308 LD A,(HL) Print the unknown word up to the next space.
49309 CP 33
49311 JR C,MatchInputWord_CloseQuote
49313 INC HL
49314 CALL PrintCharacter
49317 JR MatchInputWord_Quote
MatchInputWord_CloseQuote 49319 LD A,34 Print a closing quote.
49321 CALL PrintCharacter
49324 LD HL,48377 Print "." and read another command.
49327 CALL PrintStringAndANewline
49330 JR Handler_UnknownWord_Retry
Prev: 49011 Up: Map Next: 49332