integrated operator recognition routine
This commit is contained in:
1 parent
1b26151a3f
commit
831bc8f453
3 files changed
+131
-44
No files matched your search
@@ -129,26 +129,22 @@ FRMEVL_got_value:
|
||||
|
||||
FRMEVL_fetch_operator:
|
||||
|
||||
// We have a value, but this is not the end of expression. We expect
|
||||
// a two argument operator here. First make sure we have enough space
|
||||
// on a stack - we will surely need it
|
||||
// We have a value, but this is not the end of expression. Check if
|
||||
// there is an operator waiting to be served
|
||||
|
||||
jsr fetch_operator
|
||||
bcs FRMEVL_calculate // branch if operator not recognized
|
||||
|
||||
// We have a two-argument operator - check if there is enough stack space
|
||||
// XXX this can probably be checked later
|
||||
|
||||
tsx
|
||||
cpx #$40 // XXX is this a safe threshold?
|
||||
bcc_16 do_FORMULA_TOO_COMPLEX_error
|
||||
|
||||
// Now look for an operator
|
||||
// XXX for now only addition operator is implemented
|
||||
// XXX check the priorities - either push to stack, or execute it immediately
|
||||
|
||||
jsr fetch_character
|
||||
cmp #$AA // check for a plus operator
|
||||
beq FRMEVL_push_value_operator
|
||||
|
||||
// Something unknown - consider this the end of expression
|
||||
|
||||
jsr unconsume_character
|
||||
|
||||
// FALTROUGH
|
||||
bcs FRMEVL_push_value_operator // branch always
|
||||
|
||||
FRMEVL_calculate: // this is the exit point for the operators
|
||||
|
||||
@@ -168,7 +164,11 @@ FRMEVL_done:
|
||||
|
||||
FRMEVL_push_value_operator:
|
||||
|
||||
// First push the return address
|
||||
// Move the operator ID in .Y
|
||||
|
||||
tay
|
||||
|
||||
// Push the return address
|
||||
|
||||
lda #>(FRMEVL_calculate - 1)
|
||||
pha
|
||||
@@ -204,16 +204,16 @@ FRMEVL_push_operator_address:
|
||||
// Push the operator address to stack, in a form
|
||||
// suitable for RTS
|
||||
|
||||
// XXX add support for other operators
|
||||
// XXX add support for other operators, use .Y
|
||||
|
||||
lda #>(oper_add - 1)
|
||||
lda operator_jumptable_hi - 1, y
|
||||
pha
|
||||
lda #<(oper_add - 1)
|
||||
lda operator_jumptable_lo - 1, y
|
||||
pha
|
||||
|
||||
// Push operator priority
|
||||
|
||||
lda #$01 // XXX add support for other operators
|
||||
lda operator_priorities - 1, y
|
||||
pha
|
||||
|
||||
// Continue
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// #LAYOUT# STD * #TAKE
|
||||
// #LAYOUT# * BASIC_0 #TAKE
|
||||
// #LAYOUT# * * #IGNORE
|
||||
|
||||
//
|
||||
// Fetches an operator - for the expression parser
|
||||
//
|
||||
// Note: does not recognize unary operators
|
||||
//
|
||||
|
||||
|
||||
fetch_operator: // XXX change the operator code to start from 0
|
||||
|
||||
// Retrieve the next character
|
||||
|
||||
jsr fetch_character
|
||||
|
||||
// Check if within range
|
||||
|
||||
sec
|
||||
sbc #$A9
|
||||
bcc fetch_operator_failed // branch if below 0
|
||||
beq fetch_operator_failed // branch 0
|
||||
|
||||
cmp #$0B
|
||||
bcs fetch_operator_failed // branch if $0B or greater
|
||||
|
||||
// Now we have to recognize '>=', '<=' and '<>' operators
|
||||
|
||||
cmp #$08
|
||||
beq fetch_operator_try_gteq
|
||||
|
||||
cmp #$0A
|
||||
beq fetch_operator_try_lteq_neq
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
fetch_operator_success:
|
||||
|
||||
clc
|
||||
rts
|
||||
|
||||
fetch_operator_failed:
|
||||
|
||||
sec
|
||||
rts
|
||||
|
||||
|
||||
fetch_operator_try_gteq:
|
||||
|
||||
// Here we distinguish between '>' and '>='
|
||||
|
||||
jsr fetch_character
|
||||
cmp #$B2 // '='
|
||||
beq !+
|
||||
|
||||
// This is a '>'
|
||||
|
||||
jsr unconsume_character
|
||||
lda #$08
|
||||
bne fetch_operator_success // branch always
|
||||
!:
|
||||
// This is a '>='
|
||||
|
||||
lda #$0B
|
||||
bne fetch_operator_success // branch always
|
||||
|
||||
|
||||
fetch_operator_try_lteq_neq:
|
||||
|
||||
// Here we distinguish between '<', '<=', and '<>'
|
||||
|
||||
jsr fetch_character
|
||||
cmp #$B2 // '='
|
||||
beq !+
|
||||
cmp #$B1 // '>'
|
||||
beq !++
|
||||
|
||||
// This is a '<'
|
||||
|
||||
jsr unconsume_character
|
||||
lda #$0A
|
||||
bne fetch_operator_success // branch always
|
||||
!:
|
||||
// This is a '<='
|
||||
|
||||
lda #$0C
|
||||
bne fetch_operator_success // branch always
|
||||
!:
|
||||
// This is a '<>'
|
||||
|
||||
lda #$0D
|
||||
bne fetch_operator_success // branch always
|
||||
Reference in new issue
Block a user