Mercurial > hg > index.cgi
annotate src/parse.s @ 125:0607e4e20702
Correct offset error for keyword table lookup
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 07 Jan 2024 20:35:51 -0700 |
parents | 8770e6f977c3 |
children | ac183a519439 |
rev | line source |
---|---|
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
1 *pragmapush list |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
2 *pragma list |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
4 ; This is the overall parsing package. This is responsible for converting program text into the internal byte code and |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
5 ; reporting any syntax errors and anything else reasonably detectable at parse time without having overly complicated |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
6 ; code analysis. |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
7 ; |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
8 ; This is a recursive descent parser. |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
9 ; |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
10 ; Entry: |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
11 ; X Points to the text to encode |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
12 ; B Nonzero to prevent generating any output (error check/length calculation only) |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
13 ; |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
14 ; Exit: |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
15 ; U Points to the encoded line |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
16 ; D Length of the encoded line |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
17 ; CC.C clear |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
18 |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
19 ; Error Exit: |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
20 ; B Error code |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
21 ; U Offset to error input |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
22 ; CC.C set |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
23 parse stb parse_noout ; save no-output flag |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
24 leay ,x ; save input pointer in a less useful register |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
25 ldu freestart ; point to start of free memory where we will build the output |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
26 pshs u ; save original free memory location |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
27 parse_nextstmt jsr parse_nexttok ; fetch the next token, return type in D |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
28 bcc parse0 ; brif we succeeded in parsing a token |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
29 parse_error puls u ; restore original free memory location - deallocate any encoding |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
30 stu freestart |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
31 ldu parse_tokenst ; get start location we started parsing the token at |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
32 rts ; return error condition |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
33 parse0 ldx #parse_stmtjump ; point to jump table for token type handler |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
34 abx ; offset to handler address |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
35 abx |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
36 jsr [,x] ; call handler |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
37 bcs parse_error ; brif handler flagged error |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
38 jsr parse_curtoken ; get the token we terminated on |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
39 cmpb #token_eot ; end of input? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
40 bne parse1 ; brif not |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
41 ldb #bc_eol ; stash an end of line op |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
42 bsr parse_write |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
43 bcs parse_error ; brif we errored out writing to the result (OM?) |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
44 tfr u,d ; calculate the length of the result |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
45 subd ,s |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
46 puls u,pc ; get pointer to start of encoded result and return (C is already clear) |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
47 parse1 cmpb #token_stmtsep ; statement separator? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
48 beq parse_nextstmt ; brif so - do another statement |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
49 cmpb #token_apos ; ' token? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
50 beq parse0 ; brif so - parse it as a new statement |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
51 comb ; set C for error |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
52 ldb #err_sn ; raise syntax error |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
53 bra parse_error |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
54 parse_write lda parse_noout ; are we doing output? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
55 beq parse_write0 ; brif so |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
56 leau 1,u ; just count up the output and don't do anything |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
57 rts |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
58 parse_write0 leax -stackheadroom,s ; calculate bottom of stack with headroom |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
59 cmpx freestart ; did the stack run into the end of the output? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
60 bhs parse_write1 ; brif not - we're good |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
61 ldb #err_om ; raise out of memory error, C already set from comparison |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
62 rts |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
63 parse_write1 stb ,u+ ; save output byte |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
64 stu freestart ; save new to of used memory |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
65 parse_noop rts ; return all clear - C clear from comparison above |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
66 parse_curtoken ldb parse_curtok ; fetch token code of current token |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
67 rts |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
68 parse_tokerr comb ; flag error - unexpected token |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
69 ldb #err_sn ; raise syntax error |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
70 rts |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
71 parse_nextchar lda ,y ; at end of input already? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
72 beq parse_curchar ; brif so |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
73 leay 1,y ; move to next input character |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
74 parse_curchar lda ,y ; fetch input character |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
75 rts |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
76 parse_nexttok bsr parse_curchar ; fetch current input |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
77 beq parse_nexttok1 ; brif end of input |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
78 parse_nexttok0 cmpa #0x20 ; space? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
79 bne parse_nexttok2 ; brif not |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
80 bsr parse_nextchar ; eat the space |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
81 bne parse_nexttok0 ; brif not end of input |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
82 parse_nexttok1 ldb #token_eot ; flag end of input |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
83 bra parse_nexttok6 ; go return it |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
84 parse_nexttok2 sty parse_tokenst ; save start of current token after skipping spaces |
124
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
85 bsr parse_toupper ; make sure we have upper case letters for matching |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
86 ldx #parse_wt ; point to keyword parsing table |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
87 bsr parse_wordtab ; go see if we have a match in the keyword table |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
88 bcc parse_nexttok6 ; brif we do - return it |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
89 ldy parse_tokenst ; return to the start of the token - pointer probably clobbered |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
90 bsr parse_curchar ; get back input character (may have been clobbered) |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
91 cmpa #'. ; leading decimal? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
92 beq parse_nexttok3 ; brif so - parse number |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
93 cmpa #'0 ; is it a digit |
124
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
94 blo parse_nexttok10 ; brif not |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
95 cmpa #'9 ; is it still a digit? |
124
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
96 bhi parse_nexttok10 ; brif not |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
97 parse_nexttok3 jmp parse_number ; go parse a number |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
98 parse_nexttok6 stb parse_curtok ; save token type |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
99 leay 1,y ; eat the input character |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
100 clra ; clear C to indicate no error (and clear Z also) |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
101 rts |
124
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
102 parse_nexttok10 cmpa #'A ; is it alpha? |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
103 blo parse_nexttok11 ; brif not |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
104 cmpa #'Z ; is it still alpha? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
105 bls parse_nexttok12 ; brif so |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
106 parse_nexttok11 comb ; flag error - unrecognized token |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
107 ldb #token_error |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
108 rts |
124
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
109 parse_nexttok12 bsr parse_nextcharu ; fetch next input character |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
110 cmpa #'0 ; is it alphanumeric? |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
111 blo parse_nexttok13 ; brif not |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
112 cmpa #'9 ; is it numeric? |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
113 bls parse_nexttok12 ; brif so - keep skipping it |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
114 cmpa #'A ; is it alpha? |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
115 blo parse_nexttok13 ; brif not |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
116 cmpa #'Z ; is it still alpha? |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
117 bls parse_nexttok12 ; brif so - keep skipping it |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
118 parse_nexttok13 tfr y,d ; calculate length of identifier |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
119 subd parse_tokenst |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
120 std val0+val.strlen ; save it for reference |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
121 ldb #token_ident ; indicate an identifier (variable name, etc.) |
8770e6f977c3
Rework parser to use parse_wordtab for symbols too
William Astle <lost@l-w.ca>
parents:
123
diff
changeset
|
122 rts ; return result (C will be clear from SUBD above) |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
123 parse_nextcharu bsr parse_nextchar ; fetch next input character |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
124 beq parse_toupper0 ; brif end of input |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
125 parse_toupper cmpa #'a ; is it lower case alpha? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
126 blo parse_toupper0 ; brif not |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
127 cmpa #'z ; is it still lower case alpha? |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
128 bhi parse_toupper0 ; brif not |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
129 suba #0x20 ; adjust to upper case alpha |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
130 parse_toupper0 rts ; Z only set here if input was zero entering from parse_nextcharu |
123
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
131 ; This routine parses tokens using the table at parse_wordtab. The table is structured as follows: |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
132 ; |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
133 ; * two bytes which contain the length of the table less the two bytes for this length value |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
134 ; * a sequence of entries consisting of a single byte matching character and a token code followed |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
135 ; by an optional sub table, structured exactly the same way. |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
136 ; |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
137 ; The optional subtable will be present if the token code is token_eot |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
138 ; |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
139 ; If the character match is negative, it means a lookahead failed. The negative value is the number |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
140 ; of characters to unget and the token code is the token value to return. No other entries after this |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
141 ; in a table will be considered since thie negative match is a global match. |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
142 ; |
123
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
143 ; When a token_eot match is found, if there are no further characters in the input, the match is |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
144 ; determined to be invalid and processing continues with the next entry. |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
145 parse_wordtab0 leas 3,s ; clean up stack for sub table handling |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
146 parse_wordtab pshs a,x ; save input character and start of table |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
147 ldd ,x++ ; get length of this table |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
148 addd 1,s ; calculate the address of the end of the table |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
149 std 1,s ; save end address for comparison later |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
150 lda ,s ; get back input character |
125
0607e4e20702
Correct offset error for keyword table lookup
William Astle <lost@l-w.ca>
parents:
124
diff
changeset
|
151 parse_wordtab1 ldb 1,x ; fetch token code for this entry |
123
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
152 cmpa ,x++ ; does this entry match? |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
153 bne parse_wordtab4 ; brif not |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
154 cmpb #token_eot ; is it indicating a sub table? |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
155 bne parse_wordtab6 ; brif not |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
156 bsr parse_nextcharu ; fetch next input character (for sub table match) |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
157 bne parse_wordtab0 ; brif we are going to check the sub table |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
158 parse_wordtab2 ldd ,x++ ; fetch length of sub table |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
159 leax d,x ; move past sub table |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
160 parse_wordtab3 lda ,s ; get back input character |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
161 cmpx 1,s ; are we at the end of the table? |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
162 blo parse_wordtab1 ; brif not - check another entry |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
163 comb ; indicate no match |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
164 puls a,x,pc ; clean up stack and return |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
165 parse_wordtab4 lda -2,x ; get the match character |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
166 bmi parse_wordtab5 ; brif negative - lookahead fail |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
167 cmpb #token_eot ; is there a sub table to skip? |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
168 beq parse_wordtab2 ; brif so - skip sub table |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
169 bra parse_wordtab3 ; otherwise just move to the next entry |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
170 parse_wordtab5 leay a,y ; move back the specified number of characters |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
171 parse_wordtab6 clra ; clear C to indicate a match |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
172 puls a,x,pc ; clean up stack and return |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
173 parse_number jmp parse_tokerr |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
174 ; Parse tokens - define them in order using the macro parse_tokdef |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
175 *pragmapush list |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
176 *pragma nolist |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
177 parse_toknum set 0 |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
178 parse_tokdef macro noexpand |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
179 \1 equ parse_toknum |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
180 parse_toknum set parse_toknum+1 |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
181 fdb \2 |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
182 endm |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
183 *pragmapop list |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
184 parse_stmtjump parse_tokdef token_error,parse_tokerr |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
185 parse_tokdef token_eot,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
186 parse_tokdef token_lt,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
187 parse_tokdef token_le,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
188 parse_tokdef token_gt,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
189 parse_tokdef token_ge,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
190 parse_tokdef token_eq,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
191 parse_tokdef token_ne,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
192 parse_tokdef token_reltrue,parse_noop // always true relational operator |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
193 parse_tokdef token_stmtsep,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
194 parse_tokdef token_apos,parse_rem |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
195 parse_tokdef token_special,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
196 parse_tokdef token_bang,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
197 parse_tokdef token_hash,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
198 parse_tokdef token_dollar,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
199 parse_tokdef token_percent,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
200 parse_tokdef token_amp,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
201 parse_tokdef token_oparen,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
202 parse_tokdef token_cparen,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
203 parse_tokdef token_star,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
204 parse_tokdef token_plus,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
205 parse_tokdef token_comma,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
206 parse_tokdef token_minus,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
207 parse_tokdef token_slash,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
208 parse_tokdef token_semi,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
209 parse_tokdef token_at,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
210 parse_tokdef token_exp,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
211 parse_tokdef token_ident,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
212 parse_tokdef token_rem,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
213 parse_tokdef token_return,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
214 parse_tokdef token_run,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
215 parse_tokdef token_data,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
216 parse_tokdef token_else,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
217 parse_tokdef token_end,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
218 parse_tokdef token_stop,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
219 parse_tokdef token_sub,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
220 parse_tokdef token_let,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
221 parse_tokdef token_list,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
222 parse_tokdef token_new,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
223 parse_tokdef token_not,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
224 parse_tokdef token_print,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
225 parse_tokdef token_pop,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
226 parse_tokdef token_to,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
227 parse_tokdef token_and,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
228 parse_tokdef token_or,parse_noop |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
229 parse_tokdef token_go,parse_noop |
123
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
230 parse_tokdef token_as,parse_noop |
5681cdada362
Redo keyword table handling to handle keywords differing in length
William Astle <lost@l-w.ca>
parents:
121
diff
changeset
|
231 parse_tokdef token_asc,parse_noop |
121
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
232 parse_rem rts |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
233 |
5d5472b11ccd
Initital skeleton of separation of separate parsing scheme
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
234 *pragmapop list |