From fef124bceac9699a2deaa0f4dd0b9409c54f0f37 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 7 Jun 2020 04:44:31 +0200 Subject: [PATCH] expression evaluator now supports brackets --- c64/basic/engine/ad9e.frmevl.s | 25 +++++++++++++++++++++++-- c64/basic/operators/oper_plus.s | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/c64/basic/engine/ad9e.frmevl.s b/c64/basic/engine/ad9e.frmevl.s index e5d27ddf..9bb83962 100644 --- a/c64/basic/engine/ad9e.frmevl.s +++ b/c64/basic/engine/ad9e.frmevl.s @@ -45,7 +45,7 @@ FRMEVL_loop: cmp #$22 // check for opening quote beq FRMEVL_fetch_string cmp #$28 // check for opening bracket - beq_16 do_NOT_IMPLEMENTED_error // XXX + beq_16 FRMEVL_handle_bracket cmp #$7F // check for a token bcc FRMEVL_fetch_float @@ -65,6 +65,18 @@ FRMEVL_loop: jmp do_SYNTAX_error +FRMEVL_handle_bracket: + + // Brackets are easy to handle - just call FRMEVL recursively + // and consume the closing bracket afterwards + + jsr FRMEVL + jsr fetch_character + cmp #$29 // closing bracket + beq FRMEVL_got_value + + jmp do_SYNTAX_error + FRMEVL_fetch_float: // XXX implement this @@ -125,6 +137,8 @@ FRMEVL_fetch_operator: // Something unknown - consider this the end of expression + jsr unconsume_character + // FALTROUGH FRMEVL_calculate: // this is the exit point for the operators @@ -145,7 +159,14 @@ FRMEVL_done: FRMEVL_push_value_operator: - // First push the value in FAC1/ARG1 + // First push the return address + + lda #>(FRMEVL_calculate - 1) + pha + lda #<(FRMEVL_calculate - 1) + pha + + // Push the value in FAC1/ARG1 ldx VALTYP bmi FRMEVL_push_string diff --git a/c64/basic/operators/oper_plus.s b/c64/basic/operators/oper_plus.s index d330a88a..97822b14 100644 --- a/c64/basic/operators/oper_plus.s +++ b/c64/basic/operators/oper_plus.s @@ -39,4 +39,4 @@ oper_plus_strings: // XXX merge strings here - jmp FRMEVL_calculate + rts