chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sail / _s / getToken
1 ;
2 ; getToken.s
3 ;
4 ; The getting of the next token from the input file
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard Header ------------------------------------------------------
10
11                 GET     libs:header
12                 GET     libs:swis
13
14                 GET     libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18                 GET     sh.anchor
19
20 ;----- Main code ------------------------------------------------------------
21
22                 AREA    |TermScript$$Code|,CODE,READONLY
23
24 ; --- getToken ---
25 ;
26 ; On entry:     R9 == previous token, or -1
27 ;               R10 == pointer into the tokenised buffer
28 ;               R12 == anchor block pointer
29 ;
30 ; On exit:      R7 == token class of token read
31 ;               R8 == index of token in token class
32 ;               R9 == new lookahead token
33 ;               R10 == moved on to the first character after the rvalue
34 ;
35 ; Use:          Tries to read an token from the current input line
36
37                 EXPORT  getToken
38 getToken        ROUT
39
40 10getToken      CMP     R9,#10                  ;Is it a newline?
41                 BEQ     %20getToken             ;A newline -- bump line count
42                 LDRB    R9,[R10],#1             ;Load a byte
43                 CMP     R9,#31                  ;Is it an implicit newline?
44                 BEQ     %20getToken             ;Yes -- bump line counter
45
46 15getToken      ADR     R8,tokClasses           ;Point to class table
47                 LDR     R8,[R8,R9,LSL #1]
48                 AND     R7,R8,#&FF
49                 AND     R8,R8,#&FF00
50                 MOV     R8,R8,LSR #8
51                 MOVS    PC,R14                  ;Return to caller
52
53 20getToken      LDR     R7,tsc_line             ;Yes -- get current line
54                 ADD     R7,R7,#1                ;Increment line num
55                 STR     R7,tsc_line             ;And save new line number
56                 LDRB    R9,[R10],#1             ;Load a byte
57                 CMP     R9,#31                  ;Should we ignore this char?
58                 BEQ     %20getToken             ;Yes -- look for the next
59                 B       %15getToken
60
61                 GET     sh.tokClasses
62
63                 LTORG
64
65 ;----- That's all, folks ----------------------------------------------------
66
67                 END