From f7e8e72b819d5231c184197a9209ca3e13a605e6 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Mon, 15 Jun 2026 12:06:48 +0300 Subject: [PATCH] fixed nested if logic --- lttb-impl-notes.md | 2 +- lttb.tcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lttb-impl-notes.md b/lttb-impl-notes.md index 819ebf1..8fdf447 100644 --- a/lttb-impl-notes.md +++ b/lttb-impl-notes.md @@ -171,7 +171,7 @@ Conditionally execute the statement that follows the expressions with the relati 3. Set the string `EXPR1` to everything from the start of `STMT` to the character at position `ROPOS - 1` inclusively. 4. Set the string `REST` to everything from the position `ROEND + 1` to the end of `STMT` inclusively. 5. Initialize the integer position variable `THENPOS` to -1. -6. Pick the next keyword `KW` from this list in this particular order: `THEN LET = RETURN GOSUB INPUT PRINT GOTO END IF`. Go to step 11 when the list is exhausted. +6. Pick the next keyword `KW` from this list in this particular order: `THEN IF LET = RETURN GOSUB INPUT PRINT GOTO END`. Go to step 11 when the list is exhausted. 7. Set `THENPOS` to the first position of the currently iterated keyword `KW` inside `REST`. If not found, go to step 6. 8. If `KW` is equal exactly to `=`, decrement `THENPOS` by 1. 9. Copy the value of `THENPOS` to another integer variable, `RESTPOS`. diff --git a/lttb.tcl b/lttb.tcl index 1f89efe..35ef317 100755 --- a/lttb.tcl +++ b/lttb.tcl @@ -150,7 +150,7 @@ proc lttb_IF {stmt} { set relop [string range $stmt $ropos $roend] set expr1 [string range $stmt 0 $($ropos-1)] set rest [string range $stmt $($roend + 1) end] - foreach kw {THEN LET {=} RETURN GOSUB INPUT PRINT GOTO END IF} { + foreach kw {THEN IF LET {=} RETURN GOSUB INPUT PRINT GOTO END} { set thenpos [string first $kw $rest] if {$thenpos > -1} { if {$kw eq {=}} {incr thenpos -1}