From dc7ebb9d424bb39d59f09b8498746beb871c46f4 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 20 Nov 2020 11:50:47 -0500 Subject: - Cleaned up a bit of the code. - Made the debug print for the CPU flags more readable. - Started work on implementing line number support into SuBAsm. --- programs/sub-suite/lexer.s | 102 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 9 deletions(-) (limited to 'programs/sub-suite/lexer.s') diff --git a/programs/sub-suite/lexer.s b/programs/sub-suite/lexer.s index fc47f10..9c3cb87 100644 --- a/programs/sub-suite/lexer.s +++ b/programs/sub-suite/lexer.s @@ -5,6 +5,7 @@ lex: ldx #0 ; Reset X. txa ; Reset A. txy ; Reset Y. + sty.d ln ; Reset the temp line number. sty.q idx0 ; Clear the first index. sty.q idx1 ; Clear the second index. sty.q idx2 ; Clear the third index. @@ -13,19 +14,74 @@ lex: sty.q t_str ; Clear the token string. sty.q t_sym ; Clear the token symbol. sty regb ; Clear the isop flag. + sty islinenum ; Clear the islinenum flag. +; jsr init_lex ; Initialize the lexeme buffer. +;@checklnum: ; lda (ptr), y ; Get a character from the line. ; pha ; Preserve the character. ; jsr isdigit ; Is this character a digit? ; pla ; Get the character back. +; bne @checkidx ; No, so start checking the index. +; pha ; Preserve the character. +; jsr isdelm ; Yes, so get the delimiter type. +; and #$10 ; Is this character whitespace? +; pla ; Get the character back. +; beq @checkidx ; Yes, so start checking the index. +; sta (ptr3), y ; No, so copy the character into the lexeme buffer. +; iny ; Increment the string index. +; bra @checklnum ; Keep looping. +;@checkidx: +; sty.q idx0 ; Set the first index to the string index. +; sty islinenum ; Set the islinenum flag to the string index. +; tya ; Is the string index non-zero? +; beq @nolnum ; No, so treat it as a completly new line. +; and #0 ; Yes, so terminate the lexeme buffer. +; sta (ptr3), y ; +; lda.q ptr3 ; Setup arguments for strtoull. +; pha.q ; +; and #0 ; Reset A. +; lda #10 ; Set the base to 10. +; pha ; +; jsr strtoull ; +; sta.d ln ; Set the temp line number to the converted value. +; pla ; Cleanup the argument frame. +; pla.q ; +; and #0 ; Reset A. +; bra @getline ; Start getting the tokenized line. +;@nolnum: +; lda.d linenum ; Get the global line number. +; sta.d ln ; Set the temp line number to to global line number. +; and #0 ; Reset A. +; sta.q cline ; Reset the current line pointer. ;@getline: -; ldb #1 ; Set the second pointer -; lda.q lline ; to the last line. +; tay ; Reset Y. +; lda.q cline ; Is the current line NULL? +; bne @linepc ; No, so set the assembler's program counter to the line's address. +; lda #ln ; Yes, so create a new tokenized line. +; jsr malloc ; +; sta.q cline ; Set the current line to the new tokenized line. +; lda.q lline ; Is the last line NULL? +; beq @firstline ; Yes, so set the first line. +;@nextlline: +; ldb #1 ; No, so set the second pointer to the last line. +; jsr set_ptr ; +; ldy #ln.next ; Set the next last line to the current line. +; lda.q cline ; +; sta.q (ptr2), y ; +; bra @initline ; Initialize the line. +;@firstline: +; lda.q cline ; Set the first line to the current line. +; sta.q lines ; +;@initline: +; ldb #1 ; Set the second pointer to the current line. ; jsr set_ptr ; -; ldy #ln.next ; Set the index to the next line pointer. -; lda.q (ptr2), y ; Get the next line. -; jsr set_ptr ; Set the second pointer to the next line. -; sta.q cline ; Make it the current line. ; and #0 ; Reset A. +; ldy #ln.next ; Reset the next line. +; sta.q (ptr2), y ; +; ldy #ln.tok ; Reset the token. +; sta.q (ptr2), y ; +; ldy #ln.bline ; Reset the number of blank lines. +; sta.w (ptr2), y ; ; tay ; Reset Y. @loop: ldy.w idx0 ; Get the string index. @@ -255,8 +311,18 @@ ptok_dqu: lda #TOK_DQUOT ; Set the lexeme type to TOK_DQUOT. sta lex_type ; sta t_id ; Also set the token ID to TOK_DQUOT. - lda.d ptr3 ; Get the address of the lexeme buffer. +; lda.d ptr3 ; Get the address of the lexeme buffer. + lda.q idx1 ; Get the index of the lexeme buffer. + inc ; Increment it by one to get the size. + jsr malloc ; Make a new string. + ldb.q ptr3 ; Get the address of the lexeme buffer. + ldy.q idx1 ; Get the size of the lexeme buffer + 1. + iny ; + jsr memcpy ; Copy the string in the lexeme buffer into the new string. sta.q t_str ; Save it in the token string. + and #0 ; Reset A. + tab ; Reset B. + ldy.q idx0 ; Get the string index back. @end: jsr make_tok ; Create the token. rts ; End of parse_ptok. @@ -272,8 +338,17 @@ ptok_squ: lda #TOK_SQUOT ; Set the lexeme type to TOK_SQUOT. sta lex_type ; sta t_id ; Also set the token ID to TOK_SQUOT. - lda.d ptr3 ; Get the address of the lexeme buffer. + lda.q idx1 ; Get the index of the lexeme buffer. + inc ; Increment it by one to get the size. + jsr malloc ; Make a new string. + ldb.q ptr3 ; Get the address of the lexeme buffer. + ldy.q idx1 ; Get the size of the lexeme buffer + 1. + iny ; + jsr memcpy ; Copy the string in the lexeme buffer into the new string. sta.q t_str ; Save it in the token string. + and #0 ; Reset A. + tab ; Reset B. + ldy.q idx0 ; Get the string index back. @end: jsr make_tok ; Create the token. rts ; End of parse_ptok. @@ -291,8 +366,17 @@ ptok_scol: lda #TOK_SCOLN ; Set the lexeme type to TOK_SCOLN. sta lex_type ; sta t_id ; Also set the token ID to TOK_SCOLN. - lda.d ptr3 ; Get the address of the lexeme buffer. + lda.q idx1 ; Get the index of the lexeme buffer. + inc ; Increment it by one to get the size. + jsr malloc ; Make a new string. + ldb.q ptr3 ; Get the address of the lexeme buffer. + ldy.q idx1 ; Get the size of the lexeme buffer + 1. + iny ; + jsr memcpy ; Copy the string in the lexeme buffer into the new string. sta.q t_str ; Save it in the token string. + and #0 ; Reset A. + tab ; Reset B. + ldy.q idx0 ; Get the string index back. @end: jsr make_tok ; Create the token. rts ; End of parse_ptok. -- cgit v1.2.3-13-gbd6f