In the article Using Basic's Token Table (RISC User Volume 2 Issue 5), we stated that Basic does not provide a routine to tokenise a Basic keyword. Roger Wilson, author of Basic V, has pointed out that in fact there is such a routine.
The routine in question is called MATCH, and it is accessed in a similar way to the TOKENADDR routine described in the original article. Lines 30 to 140 of the program below find the address of MATCH which is &3833B5C in RISC OS Basic 1.04.
Using MATCH is straightforward. The variable B% must point to the location in memory of the text to be tokenised (terminated with a carriage return), and C% to a further block of memory in which to store the result. D% and E% should then be set to zero, and the routine called using CALL match. The string pointed to by A% is not limited to a single token - in fact, this routine can be used to tokenise an entire line. To clarify this, the program below will take a line and tokenise it using MATCH. The result is then printed out as a series of hex bytes. Initially, try this routine with just a single keyword.
For more details of the MATCH routine refer to pages 234 and 235 of the Archimedes User Guide.
10 REM > MatchDemo
20 DIM code 1000,in 256,out 256
30 FOR pass=0 TO 2 STEP 2
40 P%=code:[OPT pass
50 LDR R0,[R14,#&48]:TST R0,#&800000
60 BICEQ R0,R0,#&FF000000
70 ORRNE R0,R0,#&FF000000
80 ADD R1,R14,#&50
90 ADD R0,R1,R0,LSL #2
100 ADR R1,temp:STR R0,[R1]
110 MOV PC,R14
120 .temp EQUD 0:]
130 NEXT:CALL code
140 match=!temp
150 REPEAT
160 INPUT "Enter line " line$
170 $in=line$
180 B%=in:C%=out:D%=0:E%=0
190 CALL match
200 WHILE ?C% <> 13
210 PRINT RIGHT$("0"+STR$~?C%,2);" ";
220 C%+=1:ENDWHILE
230 PRINT'
240 UNTIL FALSE