Improve code readability
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 23 Feb 2025 12:07:12 +0000 (14:07 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 23 Feb 2025 12:07:12 +0000 (14:07 +0200)
Math/Truth table calculator/truth.bas

index 93db702..d40db74 100755 (executable)
@@ -24,7 +24,7 @@
 '   NOT ( Keyboard shortcut: 5 )\r
 \r
 DECLARE SUB removeRedundancies (startIndex!, endIndex!, removalCount!)\r
-DECLARE SUB getP (a!, b!)\r
+DECLARE SUB getOperatorPriority (a!, b!)\r
 DECLARE SUB movM (x1!, n!)\r
 DECLARE SUB lihts (x1, x2, l)\r
 DECLARE SUB clearScreenBuffer ()\r
@@ -64,22 +64,23 @@ FOR a = 1 TO 50
 NEXT a\r
 END SUB\r
 \r
-SUB getP (a, b)\r
+SUB getOperatorPriority (operator, priority)\r
 ' Determines the priority of logical operators\r
-SELECT CASE a\r
-    CASE 5\r
-        b = 1\r
-    CASE 3, 4\r
-        b = 2\r
-    CASE 2\r
-        b = 3\r
-    CASE 1\r
-        b = 4\r
-    CASE 40, 41\r
-        b = 100\r
+SELECT CASE operator\r
+    CASE 5   ' NOT\r
+        priority = 1\r
+    CASE 3, 4  ' OR, AND\r
+        priority = 2\r
+    CASE 2   ' Implies\r
+        priority = 3\r
+    CASE 1   ' Equivalent\r
+        priority = 4\r
+    CASE 40, 41  ' Parentheses\r
+        priority = 100\r
 END SELECT\r
 END SUB\r
 \r
+\r
 SUB lahend (x1, x2)\r
 ' Analyzes and prepares the logical equation for solving\r
 DIM muu(65 TO 122)\r
@@ -276,7 +277,7 @@ SUB removeRedundancies (startIndex, endIndex, removalCount)
     a = startIndex\r
 26  IF tehe(a) = 40 THEN\r
         ' We found an opening parenthesis. Now let's see if it can be removed.\r
-        IF a = startIndex THEN p1 = 100 ELSE getP tehe(a - 1), p1\r
+        IF a = startIndex THEN p1 = 100 ELSE getOperatorPriority tehe(a - 1), p1\r
 \r
         c = a\r
         d = 1\r
@@ -290,14 +291,14 @@ SUB removeRedundancies (startIndex, endIndex, removalCount)
         ' meaning we can check operator priority inside.\r
         IF d = 1 THEN\r
             IF (tehe(c) > 0) AND (tehe(c) <= 5) THEN\r
-                getP tehe(c), b\r
+                getOperatorPriority tehe(c), b\r
                 IF b > p2 THEN p2 = b\r
             END IF\r
         END IF\r
 \r
         IF d > 0 THEN GOTO 25\r
 \r
-        IF c + 1 > currentEnd THEN p3 = 100 ELSE getP tehe(c + 1), p3\r
+        IF c + 1 > currentEnd THEN p3 = 100 ELSE getOperatorPriority tehe(c + 1), p3\r
 \r
         ' If the operator outside is higher priority than what's inside,\r
         ' we can safely remove the parentheses.\r