From d28cba3b3359f7c516296d4be6250d22cab31088 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 23 Feb 2025 14:07:12 +0200 Subject: [PATCH] Improve code readability --- Math/Truth table calculator/truth.bas | 33 ++++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Math/Truth table calculator/truth.bas b/Math/Truth table calculator/truth.bas index 93db702..d40db74 100755 --- a/Math/Truth table calculator/truth.bas +++ b/Math/Truth table calculator/truth.bas @@ -24,7 +24,7 @@ ' NOT ( Keyboard shortcut: 5 ) DECLARE SUB removeRedundancies (startIndex!, endIndex!, removalCount!) -DECLARE SUB getP (a!, b!) +DECLARE SUB getOperatorPriority (a!, b!) DECLARE SUB movM (x1!, n!) DECLARE SUB lihts (x1, x2, l) DECLARE SUB clearScreenBuffer () @@ -64,22 +64,23 @@ FOR a = 1 TO 50 NEXT a END SUB -SUB getP (a, b) +SUB getOperatorPriority (operator, priority) ' Determines the priority of logical operators -SELECT CASE a - CASE 5 - b = 1 - CASE 3, 4 - b = 2 - CASE 2 - b = 3 - CASE 1 - b = 4 - CASE 40, 41 - b = 100 +SELECT CASE operator + CASE 5 ' NOT + priority = 1 + CASE 3, 4 ' OR, AND + priority = 2 + CASE 2 ' Implies + priority = 3 + CASE 1 ' Equivalent + priority = 4 + CASE 40, 41 ' Parentheses + priority = 100 END SELECT END SUB + SUB lahend (x1, x2) ' Analyzes and prepares the logical equation for solving DIM muu(65 TO 122) @@ -276,7 +277,7 @@ SUB removeRedundancies (startIndex, endIndex, removalCount) a = startIndex 26 IF tehe(a) = 40 THEN ' We found an opening parenthesis. Now let's see if it can be removed. - IF a = startIndex THEN p1 = 100 ELSE getP tehe(a - 1), p1 + IF a = startIndex THEN p1 = 100 ELSE getOperatorPriority tehe(a - 1), p1 c = a d = 1 @@ -290,14 +291,14 @@ SUB removeRedundancies (startIndex, endIndex, removalCount) ' meaning we can check operator priority inside. IF d = 1 THEN IF (tehe(c) > 0) AND (tehe(c) <= 5) THEN - getP tehe(c), b + getOperatorPriority tehe(c), b IF b > p2 THEN p2 = b END IF END IF IF d > 0 THEN GOTO 25 - IF c + 1 > currentEnd THEN p3 = 100 ELSE getP tehe(c + 1), p3 + IF c + 1 > currentEnd THEN p3 = 100 ELSE getOperatorPriority tehe(c + 1), p3 ' If the operator outside is higher priority than what's inside, ' we can safely remove the parentheses. -- 2.20.1